ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Label Click to open Word Document (https://www.excelbanter.com/excel-programming/415468-label-click-open-word-document.html)

NateBuckley

Label Click to open Word Document
 
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!

Gary''s Student

Label Click to open Word Document
 
ActiveWorkbook.FollowHyperlink Address:="file:///C:\Temp\Number.doc"
--
Gary''s Student - gsnu200799

Dave Peterson

Label Click to open Word Document
 
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

NateBuckley wrote:

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!


--

Dave Peterson

NateBuckley

Label Click to open Word Document
 
Thanks a lot. One of those simple things I've not done yet and couldn't
remember.

Thanks for your guiding reply.



"Gary''s Student" wrote:

ActiveWorkbook.FollowHyperlink Address:="file:///C:\Temp\Number.doc"
--
Gary''s Student - gsnu200799


Gary''s Student

Label Click to open Word Document
 
You are very welcome!

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


"NateBuckley" wrote:

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

Thanks for your guiding reply.



"Gary''s Student" wrote:

ActiveWorkbook.FollowHyperlink Address:="file:///C:\Temp\Number.doc"
--
Gary''s Student - gsnu200799



All times are GMT +1. The time now is 12:00 AM.

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