If you write macros called FileSave and FileSaveAs, they will run in place
of the built-in commands.
Alternatively, you can trap the DocumentBeforeSave event.
> Hi
>
[quoted text clipped - 23 lines]
>
> Thanks
Thanks for that, its not working quite right, though nearly right.
Code I now have is:
Sub FileSave()
'
' FileSave Macro
' Saves the active document or template
'
Dim rw As Row
Dim celltext As String
Dim tbl As Table
For Each tbl In ActiveDocument.Tables
For Each rw In tbl.Rows
rw.Select
celltext = rw.Cells(1).Range.Words.First.Text
If celltext = "blah di blah" Then
MsgBox "This is a blah di blah Document and needs to be Emailed"
End If
Next
Next
ActiveDocument.Save
End Sub
It works if I have only one word in the cell, but will not recognise a
phrase of 3 words ie - recognises Blah if it is the only word in the cell,
but not Blah di Blah in the cell. I want it to pick out a particular string
of words. Something to do with "First" perhaps, I'm not sure.
Can anyone help
> Hi
>
[quoted text clipped - 21 lines]
>
> Thanks
elle0612 - 20 Aug 2006 19:41 GMT
This is another piece of code I've tried that isn't working, I'm not at all
sure what I'm doing wrong. There's no message box popping up.
Sub FileSave()
> '
> ' FileSave Macro
> ' Saves the active document or template
Dim oCell As Cell
Dim oRow As Row
For Each oRow In Selection.Tables(1).Rows
For Each oCell In oRow.Cells
If oCell.Range.Text = "Blah di Blah" Then
MsgBox "Email this Document"
End If
Next oCell
Next oRow
ActiveDocument.Save
End Sub
> Thanks for that, its not working quite right, though nearly right.
>
[quoted text clipped - 56 lines]
> >
> > Thanks
Helmut Weber - 20 Aug 2006 20:05 GMT
Hi,
the cell's text includes the end of cell mark.
Try something like this:
If Left(oCell.Range.Text, Len(oCell.Range.Text) - 2) = "test" Then
For
celltext = rw.Cells(1).Range.Words.First.Text
If celltext = "blah di blah" Then ...
Can't be, as to Word this would be three words.
Three words can'be equal to one word. ;-)
And...
in cell 1: "TestA TestB"
Word(1) would include the following space!
I use code like this:
MsgBox "[" & Selection.Cells(1).Range.Words.First.Text & "]"
or
MsgBox "[" & Selection.Cells(1).Range.Words(1) & "]"
HTH

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
elle0612 - 21 Aug 2006 20:06 GMT
I am discovering that the finding of text in cells is too difficult for me at
present since I'm a beginner.
Another option would be this (but I would need to send the cursor to the top
of the document to successfully accomplish it).
With Selection.Find
.Text = "Test One Two Three"
.forward = True
.Match Whole Word = True
End With
If Selection.Find.Execute = True Then
MsgBox "Test One Two Three has been found"
End If
Is there any code I can add above the "With Selection.Find" to send the
cursor to the top of the page, or in the header even, so that it will find
the words further down the page???
Thanks - getting desperate now.
> Hi,
>
[quoted text clipped - 22 lines]
>
> HTH
Helmut Weber - 21 Aug 2006 21:34 GMT
Hi elle0612,
>I am discovering that the finding of text in cells is too difficult for me at
>present since I'm a beginner.
Keep on, after a while you'll do it like nothing.
Everyone, even the celebrities here have been beginners.
Sub Test56649()
Dim rngDcm As Range
Dim FoundInTables As Long
Dim FoundElseWhere As Long
Set rngDcm = ActiveDocument.Range
With rngDcm.Find
.Text = "one two three"
While .Execute
If rngDcm.Information(wdWithInTable) Then
FoundInTables = FoundInTables + 1
End If
If .found And Not rngDcm.Information(wdWithInTable) Then
FoundElseWhere = FoundElseWhere + 1
End If
Wend
End With
If FoundInTables = 0 And FoundElseWhere = 0 Then
MsgBox "not found at all"
Else
MsgBox "inside of tables = " & FoundInTables
MsgBox "elsewhere = " & FoundElseWhere
End If
End Sub
HTH

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"