K_man
asked on
Find and replace in a MS Word Document from Access, without any code in the word docs
heya again guys
I have a form that opens a Word document that the user chooses from a list of about 100 or so possible standard letters they send out. All of the documents have the fields that the database can give them set up as @App_first @App_Last @app..... etc etc
what I need to know is what code to put in the following blank spot:
Function CreateDoc()
Dim myWord As Word.Application
Dim myDoc As Word.Document
Set myWord = New Word.Application
Debug.Print docToOpen
Set myDoc = myWord.Documents.Open(docT oOpen)
myDoc.SaveAs ccSaveDir
myDoc.SaveAs SaveDir
myWord.Visible = True
'INSERT FIND AND REPLACE CODE HERE LATER
Set myDoc = Nothing
Set myWord = Nothing
End Function
I have all the needed variables stored that have to go in it, I just need the way to get them accross, I've tried but can't quite seem to get it right
I have a form that opens a Word document that the user chooses from a list of about 100 or so possible standard letters they send out. All of the documents have the fields that the database can give them set up as @App_first @App_Last @app..... etc etc
what I need to know is what code to put in the following blank spot:
Function CreateDoc()
Dim myWord As Word.Application
Dim myDoc As Word.Document
Set myWord = New Word.Application
Debug.Print docToOpen
Set myDoc = myWord.Documents.Open(docT
myDoc.SaveAs ccSaveDir
myDoc.SaveAs SaveDir
myWord.Visible = True
'INSERT FIND AND REPLACE CODE HERE LATER
Set myDoc = Nothing
Set myWord = Nothing
End Function
I have all the needed variables stored that have to go in it, I just need the way to get them accross, I've tried but can't quite seem to get it right
and 1 more line
myDoc.Selection.Find.Execu te Replace:=wdReplaceAll
myDoc.Selection.Find.Execu
ASKER
I get an "Object doesn't support this property or method on the myDoc.Selection.wholestory
looks so very promising tho
ok, ill take a proper look at it.
Dave
Dave
ASKER
ah, myDoc was my document object, myWord was the word.application
I really should start hitting ctrl space more
and thank you ! it works
just one more thing though, how do I stop it from having the whole document selected when its finished ?
I really should start hitting ctrl space more
and thank you ! it works
just one more thing though, how do I stop it from having the whole document selected when its finished ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can select the first word, not sure about no selection sorry
oWord.ActiveWindow.Selecti on.Words(1 ).Select
oWord.ActiveWindow.Selecti
ASKER
On a slightly different note..
There are about eh.. something like 20 things I need to check for so I'm goign to need to make it a function, Is it better to pass the word object through to the function or to declare the word object as a global, or can I put the function itself inside the sub that already has the declaration (I could do that in Jade but not sure about Access)
Hmmm.. Not too sure what would be faster, need to do some tests, but im guessing that declaring the word object as a global would use less memory.
ASKER
you the man
I just ended up passing it
I'll give you the points for this then post part two, don't go anywhere
I just ended up passing it
I'll give you the points for this then post part two, don't go anywhere
With myDoc.selection.Find
.Text = "A"
.Replacement.Text = "B"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
end with
Hope this helps
Dave