Using an Excel macro to open a Word File
Say you use xl2003 and your users are using xl97-xl2003.
When you explicitly set the reference, then those who don't have the same
version of office as you could have trouble (always have trouble???).
But I would use the reference while developing the code. I get all those
intellisense and autocomplete features in the VBE.
But when I'm ready to release it to others, I'll get rid of the references,
declare any constants I used and fix my DIMs to be more generic (As Object).
I don't think it's weaker--it'll probably be a bit slower (but I can't notice
the difference).
K Dales wrote:
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
--
Dave Peterson
|