Command Button- Open Word Doc

S

Stephen Baer

Hi, I'm pretty good at VBA, but I'm experiencing something new. I'm designing
an Outlook form on our Terminal Server. I was getting ready to insert some
code for a command button, similar to the thread "XLsheet Button Control to
Lauch form the Public Drive" in this forum. I'll be openinging a Word Doc
instead, but when I went to view the code, I got "Microsoft Script Editor, "
instead of the vba code interface. How does this work? Does it use the same
basic format? I also am worried that the Outlook "Use Word as the email
editor" option might give me problems, since Word will be open already. Here
is the rough draft of the code I was thinking of using. Any help would be
appreciated!

Private Sub cmdHandbook_Click
Dim WApp as Word.Application
Dim stFilename, stPath as String
stPth = "P:\Public Documents\Staff\New Hire\"
stFilename = "Employee Handbook.doc"
Set WApp = New Word.Application
With WApp
.Documents.Open(FileName: stpath & stFilename, ReadOnly:=True)
.Visible=true
End With
End Sub
Unfortunately, this doesn't work. When I "run this form" I get a popup
"Expected End of Statement: Line No. 2", and yes of course I used the real
path and real doc name :)
Office 2003, btw.
Thanks in advance!
 
K

Ken Slovak - [MVP - Outlook]

All Outlook form code is VBScript code, not VBA code. The line with the
error will work if you comment out the As clause:

Dim WApp 'as Word.Application

No Outlook or Word constants or enum values, you must use the actual value
or declare a constant, etc.

All the limitations of VBS as opposed to VBA code.

See the forms pages at www.outlookcode.com for lots more information about
the quirks of designing and using Outlook forms.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top