Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
scottEfraz
 
Posts: n/a
Default Hyperlink to open .dot with a macro

I have a word .dot that has a simple macro when opened, but when I try to
open the .dot from a hyperlink the macro doesn't autostart. Any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Hyperlink to open .dot with a macro

I opened word and created a new test2.dot template file.

I put this code under the ThisDocument module:

Option Explicit
Private Sub Document_New()
MsgBox "hi from new"
End Sub
Private Sub Document_Open()
MsgBox "hi from open"
End Sub

I put a hyperlink in a cell in an excel worksheet that pointed to that test2.dot
file.

The Document_Open() event fired--but the actual template (test2.dot) opened--a
new document based on that template did NOT get created.

I think you may want to change your technique if you want a new document based
on that template to be created (and the Document_New event to fire).

I'd put a button on the worksheet that has a macro assigned to it. It could
create a new document based on that template.

Option Explicit
Sub testme()

Dim myCell As Range
Dim WdApp As Object
Dim testStr As String

Set myCell = ActiveSheet.Range("d12") 'or whatever you want

testStr = ""
On Error Resume Next
testStr = Dir(myCell.Value)
On Error GoTo 0

If testStr = "" Then
MsgBox "Template file not found!"
Exit Sub
End If

On Error Resume Next
Set WdApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Err.Clear
Set WdApp = CreateObject("Word.Application")
End If

With WdApp
.Visible = True
.Documents.Add Template:=myCell.Value, _
NewTemplate:=False, DocumentType:=0
End With

Set WdApp = Nothing

End Sub

scottEfraz wrote:

I have a word .dot that has a simple macro when opened, but when I try to
open the .dot from a hyperlink the macro doesn't autostart. Any ideas?


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Macro that will add data from multiple workbooks to the 1st open r jbsand1001 Excel Discussion (Misc queries) 0 April 23rd 05 07:52 PM
Open a hyperlink in a new page Yoav Excel Discussion (Misc queries) 1 April 17th 05 12:00 AM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
How can I set up a Macro to automatically run when I open a speci. Rick Martin Excel Discussion (Misc queries) 1 January 13th 05 05:06 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"