Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Find and replace in a MS Word Document from Access, without any code in the word docs

Posted on 2004-10-18
10
Medium Priority
?
494 Views
Last Modified: 2008-01-16
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(docToOpen)
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
0
Comment
Question by:K_man
  • 6
  • 4
10 Comments
 
LVL 34

Expert Comment

by:flavo
ID: 12342399
myDoc.selection.wholestory
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
0
 
LVL 34

Expert Comment

by:flavo
ID: 12342408
and 1 more line

myDoc.Selection.Find.Execute Replace:=wdReplaceAll
0
 

Author Comment

by:K_man
ID: 12342537

I get an "Object doesn't support this property or method on the myDoc.Selection.wholestory line

looks so very promising tho
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 34

Expert Comment

by:flavo
ID: 12342547
ok, ill take a proper look at it.

Dave
0
 

Author Comment

by:K_man
ID: 12342572
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 ?
0
 
LVL 34

Accepted Solution

by:
flavo earned 2000 total points
ID: 12342583
ok got it

With oWord.ActiveWindow.Selection.Find
         .Text = "Test"
        .Replacement.Text = "wooooo!!!!"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
End With

oWord.Selection.Find.Execute Replace:=wdReplaceAll
0
 
LVL 34

Expert Comment

by:flavo
ID: 12342602
you can select the first word, not sure about no selection sorry

oWord.ActiveWindow.Selection.Words(1).Select
0
 

Author Comment

by:K_man
ID: 12342618

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)
0
 
LVL 34

Expert Comment

by:flavo
ID: 12342654

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.
0
 

Author Comment

by:K_man
ID: 12342946
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
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question