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

Using CreateObject - talking to Word

Status
Not open for further replies.

DavidMark

Programmer
Feb 28, 2002
28
EU
This should be a simple one for those in the know. My demo code below opens Word, makes it visible, types some text then quits. How do I quit without saving? I have looked under help for 'quit' in Word and tried everything that I can. Help!!


Function TryIt()
Dim MyWord As Object
Set MyWord = CreateObject("word.application")
MyWord.Documents.Add
MyWord.Visible = True
MyWord.Selection.TypeText Text:="Type some stuff"
MyWord.Application.Quit
Set MyWord = Nothing
End Function


Thanks in advance

Dave
 
Dave

Try something like the following

Function TryIt()
Dim MyWord As Object
Dim MyDoc as word.document
Set MyWord = CreateObject("word.application")
Set MyDoc = MyWord.Documents.Add
MyWord.Visible = True
MyWord.Selection.TypeText Text:="Type some stuff"
MyDoc.saved = True
MyWord.Application.Quit
Set MyWord = Nothing
End Function

Hope this helps

sadcow
 
Hi sadcow (could do with a name here!),

I get an error saying 'Object doesn't support this property or method'

If I try 'MyWord.Application.Quit 0' it quits word without saving, which is what I want to do. Is this the correct way?

Dave
 
Try:

Function TryIt()
Dim MyWord As Object
Set MyWord = CreateObject("word.application")
MyWord.Documents.Add
MyWord.Visible = True
MyWord.Selection.TypeText Text:="Type some stuff"
MyWord.Documents.Close (wdDoNotSaveChanges)
MyWord.Quit
Set MyWord = Nothing
End Function


 
Hi mbiro,

That doesn't work either. Access assumes that 'wdDoNotSaveChanges' is a variable. trying 'MyWord.Quit False' works, I can print the text and quit without saving. Passing false (or 0) seems the only way, since access can't appreciate Word constants. I think I will call it a day on this one. Anyone know of a good site covering automation?

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top