Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Pudsters (TechnicalUser) (OP)
19 Sep 06 15:47
The following works fine from Excel with a macro button but how do I modify it to work from a cmd button click on a user form, assuming the button name is cmdButton1?

Private Sub OpenWordDoc()

Dim wdApp As Word.Application, wdDoc As Word.Document

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

Set wdDoc = wdApp.Documents.Open("C:\Filename.doc")
wdApp.Visible = True

End Sub
PHV (MIS)
19 Sep 06 15:49
Copy your code in the Click event procedure of cmdButton1 ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886

Pudsters (TechnicalUser) (OP)
19 Sep 06 15:59
Okay, I tried that but I get an error message. I commented out the extra subs. I don't know the proper way to do this?

Private Sub cmdButton1_Click()

'Private Sub OpenWordDoc()

Dim wdApp As Word.Application, wdDoc As Word.Document

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

Set wdDoc = wdApp.Documents.Open("C:\Filename.doc")
wdApp.Visible = True

'End Sub



End Sub
PHV (MIS)
19 Sep 06 16:01
I get an error message
Any chance you could post the whole message and which line is highlighted when in debug mode ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886

fumei (TechnicalUser)
19 Sep 06 16:14
Yes, when mentioning error messages we absolutely need to know what it says!

Also, could you use the code tags to post code?  Thanks.  If you are not sure how to do this, click the Process TGML link at the bottom of the message area.

Gerry
My paintings and sculpture

Pudsters (TechnicalUser) (OP)
19 Sep 06 16:15

The two lines in bold are highlighted. Compile error - User defined type not defined:



Private Sub cmdButton1_Click()

'Private Sub OpenWordDoc()

Dim wdApp As Word.Application, wdDoc As Word.Document

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

Set wdDoc = wdApp.Documents.Open("C:\Filename.doc")
wdApp.Visible = True

'End Sub



End Sub
PHV (MIS)
19 Sep 06 16:32
Either reference the Microsoft Word library or use late binding:

CODE

Private Sub cmdButton1_Click()
Dim wdApp As Object
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
  Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
wdApp.Documents.Open "C:\Filename.doc"
wdApp.Visible = True
Set wdApp = Nothing
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886

Pudsters (TechnicalUser) (OP)
19 Sep 06 16:42
Hey! That was the first thing I did, referencing MS WORD. But I went back and the checkbox was unchecked. I rechecked it and saved the file.

Now it works fine. Thanks for all of your help!!!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close