From: Neil Humphries on


"Jay Freedman" wrote:

> 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.
> .
I followed the links you provided and read the information but could not get
the hyperlink to work in Excel. I got a Cannot Find the Specified File error.

Then I changed the name of the shortcut in the Excel hyperlink by appending
..LNK to it. Now the hyperlink finds the shortcut, but opens the template for
editting rather than creating a new document from the template.

So I am back to needing to get an Excel hyperlink to open a new document
based on a template.
From: Doug Robbins - Word MVP on
If I include the following AutoOpen macro in a template

Sub AutoOpen()
Dim myForm As frmLetterForm

Set myForm = New frmLetterForm
myForm.Show vbModal
Unload myForm
Set myForm = Nothing

End Sub

and then create a hyperlink to that template in an Excel spreadsheet and
then click on that link, after clicking on the Yes button in response to the
question "Do you want to continue?" in the Microsoft Office Excel Security
Notice message that appears, the template is opened and the user form that
is in it is displayed.

Of course that is not desirable, because I would not really be wanting to
edit the template which is what would happen.

What you should be doing is putting a Button in the spreadsheet that calls a
macro in Excel that automates Word and then uses the

Documents.Add("templatepath\name")

command so that a new document is created from the template and then the
AutoNew command in the template will run.

See the article "Control Word from Excel” at:
http://www.word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm




--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.

"Neil Humphries" <NeilHumphries(a)discussions.microsoft.com> wrote in message
news:5BE2C6C2-C726-4EA2-8C48-1E78A693B8A2(a)microsoft.com...
>
>
> "Jay Freedman" wrote:
>
>> 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.
>> .
> I followed the links you provided and read the information but could not
> get
> the hyperlink to work in Excel. I got a Cannot Find the Specified File
> error.
>
> Then I changed the name of the shortcut in the Excel hyperlink by
> appending
> .LNK to it. Now the hyperlink finds the shortcut, but opens the template
> for
> editting rather than creating a new document from the template.
>
> So I am back to needing to get an Excel hyperlink to open a new document
> based on a template.

First  |  Prev  | 
Pages: 1 2
Prev: Editing Footnotes
Next: Creating Two Macros