hyperlink

K

klav

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.
 
J

Jean-Guy Marcil

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
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
K

klav

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.
 

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