PDA

View Full Version : Opening embedded word document through VBA



deveshyahoo
03-16-2009, 06:52 AM
Hi all,
I have a word document attached in a excel sheet (Sheet1). the excel sheet has a VBA code in it. i need to open the word document for the user on the click of a button placed on the form. the code for this form is written in the same excel (vba).
Can you please help me.
Thanks a lot

lucas
03-16-2009, 07:04 AM
Doesn't embedding a word doc leave you with a link for opening it? It is on the sheet if I understand correctly. So you say form. Do you mean userform?

Does the word doc have to be embedded. What if it is just in the same directory and you want to open it?

Is it a help file or something like that?

deveshyahoo
03-16-2009, 07:12 AM
Thanks Lucas for prompt reply,
the word doc is certainly a help doc embeded on the "Sheet 1" and providing some basic information.
i wanted to use a button placed on the Userform to open the doc for the user.
The doc can not go in as a part of folder coz the vba is a desktop application i have created that can be shared.

Looking forward to some directions.
Thanks

Kenneth Hobs
03-16-2009, 07:22 AM
Mabye something like:
Private Sub CommandButton1_Click()
Dim oleObject As Object
Dim wordDocument As Object

Set oleObject = ActiveWorkbook.Sheets("Sheet1").OLEObjects(1)
oleObject.Verb Verb:=xlPrimary
ActiveSheet.Range("A1").Select

Set wordDocument = oleObject.Object

wordDocument.SaveAs ("C:\test.doc")

End Sub

deveshyahoo
03-16-2009, 07:31 AM
Thank you Hobs. its wroking great.

i have commented line
'wordDocument.SaveAs ("C:\test.doc")

just to not save the doc anywhere :).
i hope it will be fine.
Thanks once again.