open Word


Posted by Loon on January 30, 2002 2:51 PM

HI
is it possible to have a macro that will open a particular word document?

Posted by Benny on January 30, 2002 2:55 PM

Use Hyperlink?

**** If this is not part of a larger macro, you can insert a hyperlink (Insert -- Hyperlink) that will open a Word document directly.

Posted by Jack in the UK on January 30, 2002 3:27 PM

Re: Use Hyperlink?

YES this can be done but if loads of hassle, word doc cant be moved or renamed, and excel set an object to open word and fire the doc open to read

To do this complex code is required in VBA, i have done this so i could set it up, but its not nice.

Also the wa you set A1 =1 soon as you hit enter from typing 1 in cell A1 the script triggers, will slow the program down a little as its always looking at the target address ie A1 every time you hit enter or calculate or save and so on.

IF you must set a formla in A1 to change to 1 on condiont as your will require, and let me know ill try to make a code to do as you as, no promises i have much to so, but it is possible to do.

I would go with hyps but they are on demand and i guess you want automatic? Right? then as i expalin is the only way and VBA script.

HTH
Jack



Posted by DK on January 31, 2002 3:40 AM

Here's some code that will open a Word document. Pay attention to the bit about references at the top of the procedure. Any probs, let me know.

D

Sub OpenWordDoc()
'In order to use this code you must set a reference to the
'Word object library by doing this. In the VB Editor click
'Tools, References. Then search for Microsoft Word n.n Object Library
'where n.n will depend on your version of Word.

Dim wdApp As Word.Application, wdDoc As Word.Document

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

Set wdDoc = wdApp.Documents.Open("C:\temp\anyolddoc.doc")

wdApp.Visible = True

'You can now do whatever you like with the Word document e.g.

wdDoc.PrintOut
wdDoc.SaveAs "C:\temp\hello.doc"
wdDoc.Activate
'etc

End Sub