From: Manfred F on 29 Sep 2009 05:21 Hi Mo, "Mo" wrote: > No, that didn't help. The timing problem, if that is it, lies more in the > autonew sequence - addglobalreference and the following msgbox. well, if You re-run the Autoexec and then add a new document, and the error still occurs, then - it is not a timimg problem. By running the Autoexec again, You are out of the execution context of startup. When You add a new document, this again happens in an own execution context. It is curious. What do You get, when You access the global variable in the debugger? Is there really only one instance of this global variable in the system? Maybe You can replace the global Variable by a global Property Get procedure. What happens then? Regards, Manfred
From: Mo on 29 Sep 2009 12:08 Hi again, 1) What do You get, when You access the global variable in the debugger? In the debugger I get the same as the msgbox shows - at execution of autonew = blank, after execution of autonew "Hello" 2) Is there really only one instance of this global variable in the system? Absolutely sure 3) Maybe You can replace the global Variable by a global Property Get procedure. What happens then? The same result as before Has anyone tried this in Windows7/Word7 and it works? Thanks, /P "Manfred F" wrote: > Hi Mo, > > "Mo" wrote: > > > No, that didn't help. The timing problem, if that is it, lies more in the > > autonew sequence - addglobalreference and the following msgbox. > > well, if You re-run the Autoexec and then add a new document, and the error > still occurs, then - it is not a timimg problem. > By running the Autoexec again, You are out of the execution context of > startup. When You add a new document, this again happens in an own execution > context. > > It is curious. What do You get, when You access the global variable in the > debugger? > Is there really only one instance of this global variable in the system? > Maybe You can replace the global Variable by a global Property Get > procedure. What happens then? > > Regards, > > Manfred
From: "Tony Jollans" My forename at my surname dot on 29 Sep 2009 17:15 I have just tried this and it doesn't work for me anywhere and, having taken a proper look at it, I have no idea how it works for you in XP. When you set a reference it affects the way individual procedures are compiled. The AutoNew procedure in the document template is compiled without the reference, at which time the global variable in the global template is not, and can not be, resolved. If you have "Option Explicit" set, you will get a compile error; if not, a local variant will be automatically created with a default (empty) value. To make it work, you need to code something like: Sub AutoNew() Application.Run "AddGlobalReference" SecondProc End Sub Sub SecondProc() MsgBox G_Variable End Sub SecondProc will be compiled when it is called and, by then, the reference to the global template will have been set and G_Variable will resolve to the global variable there. -- Enjoy, Tony www.WordArticles.com "Mo" <Mo(a)discussions.microsoft.com> wrote in message news:92013474-6FF9-4974-AADF-E9099A2EC258(a)microsoft.com... > Hi again, > > 1) What do You get, when You access the global variable in the debugger? > In the debugger I get the same as the msgbox shows - at execution of > autonew > = blank, after execution of autonew "Hello" > 2) Is there really only one instance of this global variable in the > system? > Absolutely sure > 3) Maybe You can replace the global Variable by a global Property Get > procedure. What happens then? > The same result as before > > Has anyone tried this in Windows7/Word7 and it works? > > Thanks, > /P > > "Manfred F" wrote: > >> Hi Mo, >> >> "Mo" wrote: >> >> > No, that didn't help. The timing problem, if that is it, lies more in >> > the >> > autonew sequence - addglobalreference and the following msgbox. >> >> well, if You re-run the Autoexec and then add a new document, and the >> error >> still occurs, then - it is not a timimg problem. >> By running the Autoexec again, You are out of the execution context of >> startup. When You add a new document, this again happens in an own >> execution >> context. >> >> It is curious. What do You get, when You access the global variable in >> the >> debugger? >> Is there really only one instance of this global variable in the system? >> Maybe You can replace the global Variable by a global Property Get >> procedure. What happens then? >> >> Regards, >> >> Manfred
From: Manfred F on 30 Sep 2009 02:42 Hi Mo, I didn't get the point that, in Your AutoNew routines, You set the Reference to THIS global add-in. By the way - why do You do this again and again for every new document? You should do this only once after loading the local template or even better - once at compile time (early binding). Tony is right with his comments. I would be even more cautious and call his SecondProc in a second execution context using a timer: Sub AutoNew() Application.Run "AddGlobalReference" Application.OnTime When:=Now + TimeSerial(0, 0, 0.3), _ Name:="SecondProc" End Sub Public Sub SecondProc() MsgBox G_Variable End Sub Regards, Manfred
From: Mo on 30 Sep 2009 08:21 Thanks Tony, it's a very good explanation. I'll use that. /P "Tony Jollans" wrote: > I have just tried this and it doesn't work for me anywhere and, having taken > a proper look at it, I have no idea how it works for you in XP. > > When you set a reference it affects the way individual procedures are > compiled. The AutoNew procedure in the document template is compiled without > the reference, at which time the global variable in the global template is > not, and can not be, resolved. If you have "Option Explicit" set, you will > get a compile error; if not, a local variant will be automatically created > with a default (empty) value. > > To make it work, you need to code something like: > > Sub AutoNew() > Application.Run "AddGlobalReference" > SecondProc > End Sub > > Sub SecondProc() > MsgBox G_Variable > End Sub > > SecondProc will be compiled when it is called and, by then, the reference to > the global template will have been set and G_Variable will resolve to the > global variable there. > > -- > Enjoy, > Tony > > www.WordArticles.com > > "Mo" <Mo(a)discussions.microsoft.com> wrote in message > news:92013474-6FF9-4974-AADF-E9099A2EC258(a)microsoft.com... > > Hi again, > > > > 1) What do You get, when You access the global variable in the debugger? > > In the debugger I get the same as the msgbox shows - at execution of > > autonew > > = blank, after execution of autonew "Hello" > > 2) Is there really only one instance of this global variable in the > > system? > > Absolutely sure > > 3) Maybe You can replace the global Variable by a global Property Get > > procedure. What happens then? > > The same result as before > > > > Has anyone tried this in Windows7/Word7 and it works? > > > > Thanks, > > /P > > > > "Manfred F" wrote: > > > >> Hi Mo, > >> > >> "Mo" wrote: > >> > >> > No, that didn't help. The timing problem, if that is it, lies more in > >> > the > >> > autonew sequence - addglobalreference and the following msgbox. > >> > >> well, if You re-run the Autoexec and then add a new document, and the > >> error > >> still occurs, then - it is not a timimg problem. > >> By running the Autoexec again, You are out of the execution context of > >> startup. When You add a new document, this again happens in an own > >> execution > >> context. > >> > >> It is curious. What do You get, when You access the global variable in > >> the > >> debugger? > >> Is there really only one instance of this global variable in the system? > >> Maybe You can replace the global Variable by a global Property Get > >> procedure. What happens then? > >> > >> Regards, > >> > >> Manfred > >
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Creating a master document from code Next: NoSpaceBetweenParagraphsOfSameStyle |