Using an Excel macro to open a Word File
Dave: Curious - what is the advantage of createobject over the method I have
been using? I have been using it under an assumption that it was always
better to use a more explicit reference to an object rather than more generic
methods of creating and referencing them, and that createobject was a
"weaker" way of doing this, but that was only an assumption and not based on
a very extensive knowledge of the technical aspects behind both methods -
perhaps you can illuminate me?
--
- K Dales
"Dave Peterson" wrote:
If you want to control the word document, createobject seems better.
If you just want to open the document, you could use shell or even
followhyperlink().
ActiveWorkbook.FollowHyperlink Address:="c:\path\name.doc"
An example saved from a previous post:
Option Explicit
Sub Testme()
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
myDocName = "s:\lost property master sheets\sheet3.doc"
Set WDApp = CreateObject("Word.Application")
WDApp.Visible = True 'at least for testing!
Set WDDoc = WDApp.documents.Open(Filename:=myDocName)
WDDoc.PrintOut '.printPreview while testing???
WDDoc.Close savechanges:=False
WDApp.Quit
Set WDDoc = Nothing
Set WDApp = Nothing
End Sub
lhyer wrote:
Can someone please help me with an example of what the code would look like
to open a Word file from a macro in Excel? Is it better to use the shell or
the createobject function?
--
Dave Peterson
|