Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Automation

Status
Not open for further replies.

Mats

Technical User
Feb 18, 2000
83
EU
Does anybody have some useful code for sending a string to an open word-document. I can create a code that sends the text once, but I can't figure out how to prevent a new document from being created every time I run the code. I would like for the code just to paste the text to the end of the same document as the previous.<br><br>I've tried the Microsoft knowledge base without success. I have lots of sample code but none that works the way I want it.<br><br>Thanks
 
Just a guess, but sounds like either Word is being closed down after the first text insert, or your code does not check to see if Word is running first, and if it is, just insert, otherwise open and insert.

Sounds like you're close, but you might want to post your code so someone might put you on the right track.

Dan
 
Thanks,

Actually I got the code working good enough a little time ago. I'm still wondering though if there is a way to get a handle to an instance of word that is already running. I have code to find out if a document is open, but I have no way to declare it as an object in Access without opening a new instance of word.
 
test first to see if word is open before you create a new instance of it. then you can check the document collection for your document and make it the active doc.
 
Use the GetObject method. I think Access has a good example of this. If it returns an error when you try to GetObject for Word Application, then your error handler uses OpenObject.

HTH.
 
Thanks for your help,

I think Kathryn is on to something, because I've tried to use GetObject without any luck. Now I use OpenObject and to prevent new instances of word being opened I first check to see if word.application is set, if it is the code skips that part and goes on to inserting text. How do I fix the error handler?

Thanks again,
Mats
 
With this code I can open word and insert text, but the docment remains invisible.

Dim doc As Word.Document
Set doc = GetObject(&quot;d:\test.doc&quot;)
doc.Activate
doc.Application.Visible = True
doc.Range.InsertAfter &quot;Hello&quot;
 
This is how I handle the problem in code to check if outlook is running. If Outlook is not running then the GetObject function causes an error with err.number equal to 429. In my error handler, if I have an error 429, that means that Outlook wasn't open. I set a boolean variable to tell me that I had to open Outlook, then I open Outlook and then I return to the line after.

This logic should work in your case.

****Begin code snippet****

Set outApp = GetObject(, &quot;Outlook.application&quot;)

<snip>

Driver_Err:
Select Case Err
Case 429
blnOutlookInstance = False
Set outApp = CreateObject(&quot;Outlook.application&quot;)
Resume Next

***End Code snippet***

 
Thanks,

This works for the application, but the document still remains invisible...

Mats
 
I'm sorry, I didn't realize you wanted word visible. Add the line

wrdApp.visible=true

after you assign your Word instance to your variable.
 
Does anyone have any code that integrates with access 2000 and allows strings to be read in from a test file and into a database
 
Set up a specification first (we named ours Files Import Specification) in doing the import in Access then the following code is something we use.

Set oDatabase = CurrentDb

Dim MyFile As String

MyFile = &quot;&quot;
MyFile = Dir(strCSVPath & &quot;*.csv&quot;)
oDatabase.Execute &quot;DELETE * FROM [add_files];&quot;
Do While (MyFile <> &quot;&quot;)
DoCmd.TransferText , &quot;Files Import Specification&quot;, &quot;add_files&quot;, strCSVPath & MyFile

FileCopy strCSVPath & MyFile, strArchPath & MyFile
Kill strCSVPath & MyFile
MyFile = Dir
Loop
oDatabase.Execute &quot;INSERT INTO [files] SELECT * FROM [add_files];&quot;
oDatabase.Execute &quot;UPDATE [files] INNER JOIN [add_files] ON [files].[name] = [add_files].[name] &quot; _
& &quot;SET [files].[checksum] = [add_files].[checksum], [files].[date] = [add_files].[date];&quot;


HTH

Mary :eek:)
 
Kathryn
I noticed you had a snipet of code that checked to see if Outlook was open or not. I am in the process of incorporating a similar process into my application. Would I be able to see the fully version of what you have posted? Thank you

Paul
paul_wilson74@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top