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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shell Word and open an existing document

Status
Not open for further replies.

jcaulder

Programmer
Joined
Apr 22, 2002
Messages
241
Location
US
Hi,

I am trying to open an existing Word document from an Access form. I have not been able to find a way to open the document in Word for editing. The closest switch I could find to open a document was /t which opens a NEW document with the document passed to it as a TEMPLATE. So it isn't opening the document I want opened, it's opening another document with the one I want opened as a template. My code looks like the following:

'These are the locations for the Word exe and the mailmerge document
WordDir = "C:\Program Files\Microsoft Office\Office\WINWORD.EXE"
DocLocation = "h:\users\common\ebms\docs\worddoc\second_renew.doc"


'Now shell to Word
Shell (WordDir & " /t" & """" & DocLocation & """")

Is there a switch or a command that can be used to open Word with the document at 'DocLocation' open for editing. It seems like this would be one of the most widely used switches or commands around but I can't find any documentation in Help or on the web of this simple operation.

Any advice??

Thanks!!!

Jonathan
jonathan_caulder@unc.edu
 
What version of access are you in? Can you consider using VB Automation to launch Word?

Example:

Function accessWordDoc(docName)

Dim wordApp As Word.Application
Dim wordDoc As Word.Document

' Create new hidden instance of Word.
Set wordApp = New Word.Application

Set wordDoc = wordApp.Documents.Open(FileName:=docName)

' Display document name and count of words, and then close
' document without saving changes.
With wordDoc
accessWordDoc = "'" & .Name & "' contains " & .Words.Count & " words."
.Close wdDoNotSaveChanges
End With

wordApp.Quit
Set wordApp = Nothing

End Function

You would call this function from your form using the following method.

accessWordDoc("c:\My Documents\whatever.Doc")
petersdaniel@hotmail.com
"If A equals success, then the formula is: A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut." --Albert Einstein

 
I'm using Access 2000 and Office 2000 so I'm sure I probably could use this? I'm not sure about what this function will do though. Would this allow the user to modify the document and save it as necessary? I will experiment with it and see how it works in the meantime.

Thanks for the quick response!!

Jonathan
 
Yes, this just simply opens up an existing word document that can be edited as normal

Instead of performing this section of the code,

With wordDoc
accessWordDoc = "'" & .Name & "' contains " & .Words.Count & " words."
.Close wdDoNotSaveChanges
End With

wordApp.Quit
Set wordApp = Nothing

--you can just leave the object Open and set the wndow focus to the document. petersdaniel@hotmail.com
"If A equals success, then the formula is: A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut." --Albert Einstein

 
It doesn't appear that VB is recognizing the Word.Application class in the dim wordapp as Word.Application. The object browser doesn't show it either. Maybe automation isn't available or maybe I need to make the Word object available somehow first?

Word nor Access help seems very Helpful on Automation.

The shell command was so close. Just seems kind of weird that it won't allow opening of a specific document. Guess I'll keep digging into Automation to try and figure out why it doesn't know about the Word object.

Thanks again!
 
In you VB Object browser, You need to go to Tools / References and Make sure that Micosoft Word Object Libraries are checked. petersdaniel@hotmail.com
"If A equals success, then the formula is: A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut." --Albert Einstein

 
Think I got pretty close now. . .


Dim objWord As Object
Set objWord = CreateObject("Word.Application")

Set objDoc = objWord.Documents.Open(FileName:=docName)

objWord.Visible = True

'Now don't destroy the object

This seems to be what I was missing. . .Pretty obvious stuff huh?

Thanks again for your help!
 
You're a genius!! That's what is was. . wasn't available in the object browser. Added it, now your code works just like it was. Guess I was forcing it to create the object in the code I did above. Seems to work either way. Your code is definitely the cleanest though. Everything makes sense now.

Thanks!!

J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top