Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using an Excel macro to open a Word File
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? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using an Excel macro to open a Word File
In my opinion, neither: use automation with the Word object library. Add the
reference to Word to your project and then: Dim WordApp as Word.Application Dim WordDoc as Word.Document Set WordApp = New Word.Application Set WordDoc = WordApp.Documents.Open("C:\Blah\Blah\MyDoc.doc") .... WordDoc.Close WordApp.Quit -- - K Dales "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? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using an Excel macro to open a Word File
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Word and Excel crash when I try to open a folder to get to a file | Excel Discussion (Misc queries) | |||
Open Word Doc From Excel Macro | Excel Discussion (Misc queries) | |||
open Word from excel Macro | Excel Worksheet Functions | |||
Open One Word File from Excel | Excel Programming | |||
Graph Excel Selection, Open Word File, Embed Graph Into Word | Excel Programming |