I need to insert a hyperlink in a file that will kick off a macro. What I
did was create a template (startmacro.dot) with this code:

sub autoopen()
Documents.Add Template:="mytemplate.dot"
end sub

The hyperlink simply opens the startmacro.dot, which creates a new file
basing it on the mytemplate.dot template. The "mytemplate.dot" template
contains an autonew macro which executes my code. This all works fine.

What I have been unsuccessful with is closing the original template
(startmacro.dot). Perhaps there is another way of inserting a hyperlink to
accomplish this? Any help would be appreciated. Thanks.

Re: hyperlink by Jean-Guy

Jean-Guy
Tue Oct 03 15:57:19 CDT 2006

klav was telling us:
klav nous racontait que :

> I need to insert a hyperlink in a file that will kick off a macro.
> What I did was create a template (startmacro.dot) with this code:
>
> sub autoopen()
> Documents.Add Template:="mytemplate.dot"
> end sub
>
> The hyperlink simply opens the startmacro.dot, which creates a new
> file basing it on the mytemplate.dot template. The "mytemplate.dot"
> template contains an autonew macro which executes my code. This all
> works fine.
>
> What I have been unsuccessful with is closing the original template
> (startmacro.dot). Perhaps there is another way of inserting a
> hyperlink to accomplish this? Any help would be appreciated. Thanks.

In your mytemplate.dot macro, add something like:


Dim docOpened as Documents
Dim i As Long

Set docOpened = Application.Documents

For i = 1 to docOpened.Count
If docOpened(i).Name = "startmacro.dot" Then
docOpened(i).Close wdDoNotSaveChanges
Exit Sub
End If
Next


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



RE: hyperlink by klav

klav
Wed Oct 04 14:28:02 CDT 2006

I had something like this in my file but I was getting Word
errors....however, I tried your code and it seems to be working OK. Thanks
very much.

"klav" wrote:

> I need to insert a hyperlink in a file that will kick off a macro. What I
> did was create a template (startmacro.dot) with this code:
>
> sub autoopen()
> Documents.Add Template:="mytemplate.dot"
> end sub
>
> The hyperlink simply opens the startmacro.dot, which creates a new file
> basing it on the mytemplate.dot template. The "mytemplate.dot" template
> contains an autonew macro which executes my code. This all works fine.
>
> What I have been unsuccessful with is closing the original template
> (startmacro.dot). Perhaps there is another way of inserting a hyperlink to
> accomplish this? Any help would be appreciated. Thanks.
>
>