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

Open an exisiting word document 1

Status
Not open for further replies.

jimwal0367

Programmer
Dec 3, 2005
24
GB
Is it possible to open an exisiting word document like letter.doc by using an a macro in attachmate. I have the code for opening a blank word document see below.


Sub Main()

' Declare Object Variables
Dim objApp As Object
Dim objDoc As Object
Dim objRange As Object

'if word not running, GetObject(...) will return a 429 error.
'Therefore tell macro to keep running if an error raised

On Error Resume Next

'try to grab a reference to an open instance of word
Set objApp = GetObject(, "Word.Application.8")

'if getobject(..) failed to return an object, then
If objApp Is Nothing Then

Set objApp = CreateObject("Word.Application.8")

'if objApp is still nothing, word is not installed. Exit the macro
If objApp Is Nothing Then Exit Sub

End If

'make word visible to user
objApp.Visible = True

'Create a new, blank, untitled document and assign it to objDoc
Set objDoc = objApp.Documents.Add


End Sub

Thanks
jimwal0367
 
Calculus,

Are you saying that my code will work( which I know does) or were you going to add some more code????

Slightly confused

jimwal0367
 
Your code should work. I thought that was your question.

Is your question how do you use it in EB?

calculus
 
Jim,

I think this is what your asking for.

replace
Set objDoc = objApp.Documents.Add

with
objApp.Documents.Open "your drive:\yourdocument.doc"

 
Opps, If you still need the object use this line to set it

set objdoc= objapp.Documents.Open("C:\tempchk.txt")
 
Thanks,

Everyone, I should have made my message clearer, mgwils reply was exactly what I was looking for.

Thanks

jimwal0367
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top