ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Assign a variable to a word document (https://www.excelbanter.com/excel-programming/320235-assign-variable-word-document.html)

Anson[_2_]

Assign a variable to a word document
 
Hello,

I have done this before but I lost my notes... How do you assign a variable
to a Word document when you open it? I thought the following codes would be
enough but it gives me the "type mismatch" error. Thanks for you help!

Sub xyz()

Dim WordApp As Word.Application
Dim LetterTemplate As Word.Document

Set WordApp = New Word.Application
WordApp.Visible = True
Set LetterTemplate = WordApp.Documents.Open(Filename:="Blah Blah Blah",
ReadOnly:=True)

End sub


Bob Phillips[_6_]

Assign a variable to a word document
 
Anson,

Your code works fine for me, as long as I use a fully qualified, proper doc
path.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Anson" wrote in message
...
Hello,

I have done this before but I lost my notes... How do you assign a

variable
to a Word document when you open it? I thought the following codes would

be
enough but it gives me the "type mismatch" error. Thanks for you help!

Sub xyz()

Dim WordApp As Word.Application
Dim LetterTemplate As Word.Document

Set WordApp = New Word.Application
WordApp.Visible = True
Set LetterTemplate = WordApp.Documents.Open(Filename:="Blah Blah Blah",
ReadOnly:=True)

End sub





All times are GMT +1. The time now is 05:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com