From: Neil Humphries on
I have a template which opens the save as dialog box and then opens a
userform. I want the documents created from the template to also open the
userform when the documents are opened. How do I do this? Do I need to insert
an autoopen macro into the document when it is created?
From: Jay Freedman on
Neil Humphries wrote:
> I have a template which opens the save as dialog box and then opens a
> userform. I want the documents created from the template to also open
> the userform when the documents are opened. How do I do this? Do I
> need to insert an autoopen macro into the document when it is created?

No, you don't put any macros in any document (unless you like dealing with
Word's macro virus warning popups). You put the AutoOpen (or Document_Open)
code in the template. See
http://www.word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.


From: Neil Humphries on

"Jay Freedman" wrote:

> Neil Humphries wrote:
> > I have a template which opens the save as dialog box and then opens a
> > userform. I want the documents created from the template to also open
> > the userform when the documents are opened. How do I do this? Do I
> > need to insert an autoopen macro into the document when it is created?
>
> No, you don't put any macros in any document (unless you like dealing with
> Word's macro virus warning popups). You put the AutoOpen (or Document_Open)
> code in the template. See
> http://www.word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so
> all may benefit.
>
I already had code in the ThisDocument object, but nothing was happening. I
have now discovered other code that worked when in a .docm file, but failed
when in a .dotm file. It was not a VBA issue, just the test that was being
evaluated to determine if the user was opening the master document from the
original location or a saved as copy. I fixed the code and now all works fine.

Without your response, I would have wasted a lot of time puzzling over how
documents relate to their templates rather than looking elsewhere for the
problem. Thanks.
From: Neil Humphries on


"Jay Freedman" wrote:

> Neil Humphries wrote:
> > I have a template which opens the save as dialog box and then opens a
> > userform. I want the documents created from the template to also open
> > the userform when the documents are opened. How do I do this? Do I
> > need to insert an autoopen macro into the document when it is created?
>
> No, you don't put any macros in any document (unless you like dealing with
> Word's macro virus warning popups). You put the AutoOpen (or Document_Open)
> code in the template. See
> http://www.word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so
> all may benefit.
>
If I double click on my template in windows explorer, everything works as
expected. If I open the file by clicking on a hyperlink in eXcel I get an
error message:
Run-time error '4248'
This command is not available because no document is open.

Pressing the Debug button takes me to the first line of the ThisDocument
procedure below.

Private Sub Document_Open()
IsTemplate = ActiveDocument.Path Like "*Templates*"
If IsTemplate Then
Application.Run MacroName:="FileSaveAs"
End If
Application.ActiveDocument.Activate
Application.ScreenRefresh
Main
End Sub

Why does it behave differently depending on how it is opened, and why is the
Document_Open procedure running? I expected the Document_New procedure to run.
From: Jay Freedman on
On Wed, 27 Jan 2010 08:17:02 -0800, Neil Humphries
<NeilHumphries(a)discussions.microsoft.com> wrote:

>
>
>"Jay Freedman" wrote:
>
>> Neil Humphries wrote:
>> > I have a template which opens the save as dialog box and then opens a
>> > userform. I want the documents created from the template to also open
>> > the userform when the documents are opened. How do I do this? Do I
>> > need to insert an autoopen macro into the document when it is created?
>>
>> No, you don't put any macros in any document (unless you like dealing with
>> Word's macro virus warning popups). You put the AutoOpen (or Document_Open)
>> code in the template. See
>> http://www.word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm.
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://word.mvps.org
>> Email cannot be acknowledged; please post all follow-ups to the newsgroup so
>> all may benefit.
>>
>If I double click on my template in windows explorer, everything works as
>expected. If I open the file by clicking on a hyperlink in eXcel I get an
>error message:
> Run-time error '4248'
> This command is not available because no document is open.
>
>Pressing the Debug button takes me to the first line of the ThisDocument
>procedure below.
>
>Private Sub Document_Open()
> IsTemplate = ActiveDocument.Path Like "*Templates*"
> If IsTemplate Then
> Application.Run MacroName:="FileSaveAs"
> End If
> Application.ActiveDocument.Activate
> Application.ScreenRefresh
> Main
>End Sub
>
>Why does it behave differently depending on how it is opened, and why is the
>Document_Open procedure running? I expected the Document_New procedure to run.

The behavior of Word templates is different in Windows Explorer and in
Internet Explorer (and other browsers and anything else that uses a
hyperlink). The default action in Windows Explorer is "New", while the
default action for hyperlinks is "Open". This is (sort of) documented
in http://support.microsoft.com/kb/278627.

The Document_Open procedure runs because the template itself is
opening in Word.

That KB article and
http://www.addbalance.com/word/templatesmenu.htm#Hyperlinks explain a
workaround: Make a shortcut to the template, and create the hyperlink
to point to the shortcut instead of pointing to the template itself.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
 |  Next  |  Last
Pages: 1 2
Prev: Editing Footnotes
Next: Creating Two Macros