From: Mo on
Hi,

I have posted a problem here earlier regarding code that works in
WindowsXP/Word2007 but not on Windows7/Word2007, but have received no
replies. That problem still exists. I now have another similar problem:

In a global template I store code and global variables. The global template
is in the startup directory so it gets loaded into word at word startup.
Individual templates then make use of that code and variables. This is
accomplished through an autonew macro in each individual template, that at
run-time attaches a reference to that global template. Here is the code
structure:

In the Global template:

Public G_Variable as string

Public Sub AutoExec()
G_Variable = "Hello"
End Sub

Public Sub AddGlobalReference()
ActiveDocument.AttachedTemplate.VBProject.References.AddFromFile Chr(34) &
"TheGlobalTemplateName.dotm" & Chr(34)
ActiveDocument.AttachedTemplate.Saved = True

End Sub

In the Individual templates:

Sub AutoNew()
Application.Run "AddGlobalReference"
MsgBox G_Variable
End Sub

The problem:
When a new document is created with the individual templates and the AutoNew
macro runs

* In Windows7/Word2007 the msgbox displays "" = Not desired result
* In WindowsXP/Word2007 the msgbox displays "Hello" = Desired result

To me a strange thing in Windows7/Word2007 is, that after the AutoNew macro
has finished its execution, if you in VBE, in the Immidiate Window, view the
variable (debug.print G_Variable) it displays "Hello".

Some notes:

* There are no problems with the reference setting - it is set through the
AddGlobalReference code. (If you need a
* First after the execution of the AutoNew is finished, the variable is
usable from the individual templates.

Environment:

* The latest updates are installed via Microsoft Update.

I would be glad if someone, also from Microsoft, could comment on this
problem,
Peeter
From: "Tony Jollans" My forename at my surname dot on
My guess is that this is a timing issue. Does it make a difference if you
put DoEvents before the MsgBox?

--
Enjoy,
Tony

www.WordArticles.com

"Mo" <Mo(a)discussions.microsoft.com> wrote in message
news:30F53BCD-F29E-4878-A7E4-B8A782DDD0C3(a)microsoft.com...
> Hi,
>
> I have posted a problem here earlier regarding code that works in
> WindowsXP/Word2007 but not on Windows7/Word2007, but have received no
> replies. That problem still exists. I now have another similar problem:
>
> In a global template I store code and global variables. The global
> template
> is in the startup directory so it gets loaded into word at word startup.
> Individual templates then make use of that code and variables. This is
> accomplished through an autonew macro in each individual template, that at
> run-time attaches a reference to that global template. Here is the code
> structure:
>
> In the Global template:
>
> Public G_Variable as string
>
> Public Sub AutoExec()
> G_Variable = "Hello"
> End Sub
>
> Public Sub AddGlobalReference()
> ActiveDocument.AttachedTemplate.VBProject.References.AddFromFile Chr(34) &
> "TheGlobalTemplateName.dotm" & Chr(34)
> ActiveDocument.AttachedTemplate.Saved = True
>
> End Sub
>
> In the Individual templates:
>
> Sub AutoNew()
> Application.Run "AddGlobalReference"
> MsgBox G_Variable
> End Sub
>
> The problem:
> When a new document is created with the individual templates and the
> AutoNew
> macro runs
>
> * In Windows7/Word2007 the msgbox displays "" = Not desired result
> * In WindowsXP/Word2007 the msgbox displays "Hello" = Desired result
>
> To me a strange thing in Windows7/Word2007 is, that after the AutoNew
> macro
> has finished its execution, if you in VBE, in the Immidiate Window, view
> the
> variable (debug.print G_Variable) it displays "Hello".
>
> Some notes:
>
> * There are no problems with the reference setting - it is set through the
> AddGlobalReference code. (If you need a
> * First after the execution of the AutoNew is finished, the variable is
> usable from the individual templates.
>
> Environment:
>
> * The latest updates are installed via Microsoft Update.
>
> I would be glad if someone, also from Microsoft, could comment on this
> problem,
> Peeter

From: Mo on
Thanks,

I have tried that but it makes no difference. The problem still exists: It
works in Windows XP, and has so for years, but under Windows 7 it doesn't.

Microsoft - could you please comment on this?

/P

"Tony Jollans" wrote:

> My guess is that this is a timing issue. Does it make a difference if you
> put DoEvents before the MsgBox?
>
> --
> Enjoy,
> Tony
>
> www.WordArticles.com
>
> "Mo" <Mo(a)discussions.microsoft.com> wrote in message
> news:30F53BCD-F29E-4878-A7E4-B8A782DDD0C3(a)microsoft.com...
> > Hi,
> >
> > I have posted a problem here earlier regarding code that works in
> > WindowsXP/Word2007 but not on Windows7/Word2007, but have received no
> > replies. That problem still exists. I now have another similar problem:
> >
> > In a global template I store code and global variables. The global
> > template
> > is in the startup directory so it gets loaded into word at word startup.
> > Individual templates then make use of that code and variables. This is
> > accomplished through an autonew macro in each individual template, that at
> > run-time attaches a reference to that global template. Here is the code
> > structure:
> >
> > In the Global template:
> >
> > Public G_Variable as string
> >
> > Public Sub AutoExec()
> > G_Variable = "Hello"
> > End Sub
> >
> > Public Sub AddGlobalReference()
> > ActiveDocument.AttachedTemplate.VBProject.References.AddFromFile Chr(34) &
> > "TheGlobalTemplateName.dotm" & Chr(34)
> > ActiveDocument.AttachedTemplate.Saved = True
> >
> > End Sub
> >
> > In the Individual templates:
> >
> > Sub AutoNew()
> > Application.Run "AddGlobalReference"
> > MsgBox G_Variable
> > End Sub
> >
> > The problem:
> > When a new document is created with the individual templates and the
> > AutoNew
> > macro runs
> >
> > * In Windows7/Word2007 the msgbox displays "" = Not desired result
> > * In WindowsXP/Word2007 the msgbox displays "Hello" = Desired result
> >
> > To me a strange thing in Windows7/Word2007 is, that after the AutoNew
> > macro
> > has finished its execution, if you in VBE, in the Immidiate Window, view
> > the
> > variable (debug.print G_Variable) it displays "Hello".
> >
> > Some notes:
> >
> > * There are no problems with the reference setting - it is set through the
> > AddGlobalReference code. (If you need a
> > * First after the execution of the AutoNew is finished, the variable is
> > usable from the individual templates.
> >
> > Environment:
> >
> > * The latest updates are installed via Microsoft Update.
> >
> > I would be glad if someone, also from Microsoft, could comment on this
> > problem,
> > Peeter
>
>
From: Manfred F on
Mo,

this could still be a timimg problem.
Please try and run the "AutoExec" in Your global template manually once
(again).
What happens then when You add a new document from Your individual template?

Kind Regards,

Manfred
From: Mo on
Thanks for showing interest,

No, that didn't help. The timing problem, if that is it, lies more in the
autonew sequence - addglobalreference and the following msgbox.
/P

"Manfred F" wrote:

> Mo,
>
> this could still be a timimg problem.
> Please try and run the "AutoExec" in Your global template manually once
> (again).
> What happens then when You add a new document from Your individual template?
>
> Kind Regards,
>
> Manfred