Label Click to open Word Document

N

NateBuckley

Hello, I want to be able to click on a label in a userform and do something
in the

_Click event that will open a word document.

Something like this

OpenWord(thisWorkBook.Path & "/guide/guide.doc")

I know this Function "OpenWord" doesn't exist, just wondering if anything
like it.

Thanks in advance!
 
D

Dave Peterson

Here's one that I saved:

Option Explicit
Sub testme()

'Dim WDApp As Word.Application
'Dim WDDoc As Word.Document
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
Dim WordWasRunning As Boolean
Dim testStr As String

myDocName = "C:\my documents\word\doc10.doc"

testStr = ""
On Error Resume Next
testStr = Dir(myDocName)
On Error GoTo 0
If testStr = "" Then
MsgBox "Word file not found!"
Exit Sub
End If

WordWasRunning = True
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WDApp = CreateObject("Word.Application")
WordWasRunning = False
End If

WDApp.Visible = True 'at least for testing!

Set WDDoc = WDApp.documents.Open(Filename:=myDocName)

'do more stuff????

'If WordWasRunning Then
' 'leave it running
'Else
' WDApp.Quit
'End If

Set WDDoc = Nothing
Set WDApp = Nothing

End Sub
 
N

NateBuckley

Thanks a lot. One of those simple things I've not done yet and couldn't
remember.

Thanks for your guiding reply.
 
G

Gary''s Student

You are very welcome!

The method in Peterson's post should be used if you need to control the Word
app from VBA
 

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