-
WSbjoeng
AskWoody LoungerYes it does.
It means I have done something wrong, and I (You) suddenly have solved the problem!
As I now remember from som VBA help, only one AutoExec procedure will be executed when opening/starting a template.
I tried it and it now works correct.
Thanks a lot Hans, sorry to use so mutch time just because I forgot that I had an AutoExec allready.
Best regards
and have a nice evening (time is 15:15 and I have to change to summertiers on my electric vehicle, a TH!NK. A previous norwegian battery driven car developed in Norway, bought by Ford. Very good and inexpencive, no toll road charge. Though this has nothing to do with VBA coding.)Bj
-
WSbjoeng
AskWoody LoungerYes I did,
I tried without it and then it did not work.
I have the following in the ClassModule:
Public WithEvents app As Application
Private Sub app_DocumentOpen(ByVal doc As Document)
CommonCode.PrepareNoMacroTemplate doc ‘ being the procedure in the standard module “CommonCode” to excecuted
End SubIn the module “CommonCode” I have:
Public OpenMyCls As New OpenCls
Public Sub AutoExec()
Set OpenMyCls.app = Application
MsgBox “Open works” ‘ this Msgbox is not showing
End SubPublic Sub PrepareNoMacroTemplate(doc As Document)
Debug.Print “The following document is opened: ” & doc.Name ‘ to check if it works
ThisDocument.UpdateTemplate ‘ being the procedure in ThisDocument to be strated
End SubIn ThisDocument I have:
Public Sub UpdateTemplate()
‘ update code
End SubHere I also have.
Private Sub Document_Open()
Set OpenMyCls.app = Application
MsgBox “Open works”
End Subwhich is started when I “manually” open my global template.
The initializing of “Public WithEvents app As Application” does not seem to occure, only when the global is opened (again) after Word is started.
Can it be any setting somewhere?
Rgds
Bj -
WSbjoeng
AskWoody LoungerYes I did,
I tried without it and then it did not work.
I have the following in the ClassModule:
Public WithEvents app As Application
Private Sub app_DocumentOpen(ByVal doc As Document)
CommonCode.PrepareNoMacroTemplate doc ‘ being the procedure in the standard module “CommonCode” to excecuted
End SubIn the module “CommonCode” I have:
Public OpenMyCls As New OpenCls
Public Sub AutoExec()
Set OpenMyCls.app = Application
MsgBox “Open works” ‘ this Msgbox is not showing
End SubPublic Sub PrepareNoMacroTemplate(doc As Document)
Debug.Print “The following document is opened: ” & doc.Name ‘ to check if it works
ThisDocument.UpdateTemplate ‘ being the procedure in ThisDocument to be strated
End SubIn ThisDocument I have:
Public Sub UpdateTemplate()
‘ update code
End SubHere I also have.
Private Sub Document_Open()
Set OpenMyCls.app = Application
MsgBox “Open works”
End Subwhich is started when I “manually” open my global template.
The initializing of “Public WithEvents app As Application” does not seem to occure, only when the global is opened (again) after Word is started.
Can it be any setting somewhere?
Rgds
Bj -
WSbjoeng
AskWoody LoungerThanks Hans
If I put the various code into my existing global template which “opens” when I start Word the “Public WithEvents app As Application” will not be initiated. (In the VBA editor this template is not accessible.) But if I, after Word is started, opens my global tempate then it works. (In the VBA editor this template is now accessible.)
It looks to me that when Word starts and at the same time the global template is started/opened from the startup folder the “Public WithEvents app As Application” is not activated. This seems odd to me; why isn’t it activated?
If I also place your Global.dot in my Startup it looks as it will work. But then I may have to put the relevant code into that template.
Do I have to have a separtae global template to accomplish this task?
Regards
Bj -
WSbjoeng
AskWoody LoungerThanks Hans
If I put the various code into my existing global template which “opens” when I start Word the “Public WithEvents app As Application” will not be initiated. (In the VBA editor this template is not accessible.) But if I, after Word is started, opens my global tempate then it works. (In the VBA editor this template is now accessible.)
It looks to me that when Word starts and at the same time the global template is started/opened from the startup folder the “Public WithEvents app As Application” is not activated. This seems odd to me; why isn’t it activated?
If I also place your Global.dot in my Startup it looks as it will work. But then I may have to put the relevant code into that template.
Do I have to have a separtae global template to accomplish this task?
Regards
Bj -
WSbjoeng
AskWoody LoungerOK, but have I understood it right that I should place
Private Sub Document_Open()
Set OpenCls.app = Application
MsgBox “Open works”
End Sub
in the Global template’s ThisDocumentand the other code “Public Sub FixDoc(doc As Document)” in a standard module in the Global template?
Rgds
Bj -
WSbjoeng
AskWoody LoungerOK, but have I understood it right that I should place
Private Sub Document_Open()
Set OpenCls.app = Application
MsgBox “Open works”
End Sub
in the Global template’s ThisDocumentand the other code “Public Sub FixDoc(doc As Document)” in a standard module in the Global template?
Rgds
Bj -
WSbjoeng
AskWoody Lounger(This may be a double post, I answered on Post: 320550)
Thanks Hans!
I have tried this but cannot get it working.
<Public Sub FixDoc(doc As Document)
< With doc.ActiveWindow
< .DocumentMap = True ' What exactly does these two methods?
< .DocumentMap = False
< End With
<End Sub<3. Put the following code in ThisDocument: ' I presume "ThisDocument" is the module "ThisDocument" in the Global template?
The document I'm opening does not have areference to a .dot file and thus cannot know anything about the code.This procedure in "ThisDocument" will not run:
Private Sub Document_Open()
Set myCls.app = Application
MsgBox "Open works"
End SubRgds
Bj -
WSbjoeng
AskWoody LoungerThanks Hans!
I have tried this but cannot get it working.
<Public Sub FixDoc(doc As Document)
< With doc.ActiveWindow
< .DocumentMap = True ' What exactly does these two methods?
< .DocumentMap = False
< End With
<End Sub<3. Put the following code in ThisDocument: ' I presume "ThisDocument" is the module "ThisDocument" in the Global template?
The document I'm opening does not have areference to a .dot file and thus cannot know anything about the code.This procedure in "ThisDocument" will not run:
Private Sub Document_Open()
Set myCls.app = Application
MsgBox "Open works"
End SubRgds
Bj -
WSbjoeng
AskWoody LoungerThanks Hans!
I have tried this but cannot get it working.
<Public Sub FixDoc(doc As Document)
< With doc.ActiveWindow
< .DocumentMap = True ' What exactly does these two methods?
< .DocumentMap = False
< End With
<End Sub<3. Put the following code in ThisDocument: ' I presume "ThisDocument" is the module "ThisDocument" in the Global template?
The document I'm opening does not have areference to a .dot file and thus cannot know anything about the code.This procedure in "ThisDocument" will not run:
Private Sub Document_Open()
Set myCls.app = Application
MsgBox "Open works"
End SubRgds
Bj -
WSbjoeng
AskWoody LoungerEdited by Phil Rabichow to make the link clickable – see Help #19
Thanks Phil,I continued searching and found post 350911 by Stuart and there he says:
Define everything about each of your 18 styles, except for the numbering first
Then put the cursor in a Heading 1 style, visit the bullets and numbering box and set the numbering for all 9 heading styles before you exit the box, make sure you use the More button to associate each level with the correct style.
Then put the cursor in an H1-App style, visit the bullets and numbering box and set the numbering for all 9 appendix styles before you exit
I presumably hadn’t set the two levels “before you exit” the box.
Now it looks as it works OK.
Thanks for a quick anser and good night! (It’s 23:45 and a working day tomorrow)
Regards
Bj -
WSbjoeng
AskWoody LoungerEdited by Phil Rabichow to make the link clickable – see Help #19
Thanks Phil,I continued searching and found post 350911 by Stuart and there he says:
Define everything about each of your 18 styles, except for the numbering first
Then put the cursor in a Heading 1 style, visit the bullets and numbering box and set the numbering for all 9 heading styles before you exit the box, make sure you use the More button to associate each level with the correct style.
Then put the cursor in an H1-App style, visit the bullets and numbering box and set the numbering for all 9 appendix styles before you exit
I presumably hadn’t set the two levels “before you exit” the box.
Now it looks as it works OK.
Thanks for a quick anser and good night! (It’s 23:45 and a working day tomorrow)
Regards
Bj -
WSbjoeng
AskWoody LoungerMarch 26, 2004 at 12:46 pm in reply to: What can cause extream CPU usage (Wind XP, Office 2003) #805251Thanks for the help.
Only have a Global template that is used for some things.
I will also try to turn off “Allow background saves” in the Tools/Option/Save to see if any effect.
Thaks!
Regards
Bjorn -
WSbjoeng
AskWoody LoungerMarch 26, 2004 at 12:46 pm in reply to: What can cause extream CPU usage (Wind XP, Office 2003) #805252Thanks for the help.
Only have a Global template that is used for some things.
I will also try to turn off “Allow background saves” in the Tools/Option/Save to see if any effect.
Thaks!
Regards
Bjorn -
WSbjoeng
AskWoody LoungerMarch 26, 2004 at 12:25 pm in reply to: What can cause extream CPU usage (Wind XP, Office 2003) #805241Thanks Hans,
Soory but it was not the intension to make you read all the code. Thought perhaps that it would show the way the code was made that could indicate a reason for taking so long time.
I will anyway check all the sugestions that have come in.
Regards
Bjormn
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Where’s the cache today?
by
Up2you2
3 hours, 13 minutes ago -
Ascension says recent data breach affects over 430,000 patients
by
Nibbled To Death By Ducks
6 hours, 15 minutes ago -
Nintendo Switch 2 has a remote killing switch
by
Alex5723
6 hours, 36 minutes ago -
Blocking Search (on task bar) from going to web
by
HenryW
11 hours, 16 minutes ago -
Windows 10: Microsoft 365 Apps will be supported up to Oct. 10 2028
by
Alex5723
16 hours, 23 minutes ago -
Add or Remove “Ask Copilot” Context Menu in Windows 11 and 10
by
Alex5723
16 hours, 30 minutes ago -
regarding april update and may update
by
heybengbeng
18 hours ago -
MS Passkey
by
pmruzicka
1 hour, 19 minutes ago -
Can’t make Opera my default browser
by
bmeacham
1 day, 1 hour ago -
*Some settings are managed by your organization
by
rlowe44
12 hours, 23 minutes ago -
Formatting of “Forward”ed e-mails
by
Scott Mills
1 day ago -
SmartSwitch PC Updates will only be supported through the MS Store Going Forward
by
PL1
1 day, 20 hours ago -
CISA warns of hackers targeting critical oil infrastructure
by
Nibbled To Death By Ducks
2 days, 5 hours ago -
AI slop
by
Susan Bradley
19 hours, 21 minutes ago -
Chrome : Using AI with Enhanced Protection mode
by
Alex5723
2 days, 6 hours ago -
Two blank icons
by
CR2
18 hours, 17 minutes ago -
Documents, Pictures, Desktop on OneDrive in Windows 11
by
ThePhoenix
2 days, 15 hours ago -
End of 10
by
Alex5723
2 days, 18 hours ago -
Single account cannot access printer’s automatic duplex functionality
by
Bruce
1 day, 16 hours ago -
test post
by
gtd12345
3 days ago -
Privacy and the Real ID
by
Susan Bradley
2 days, 14 hours ago -
MS-DEFCON 2: Deferring that upgrade
by
Susan Bradley
16 hours, 36 minutes ago -
Cant log on to oldergeeks.Com
by
WSJonharnew
3 days, 4 hours ago -
Upgrading from Win 10
by
WSjcgc50
1 day, 16 hours ago -
USB webcam / microphone missing after KB5050009 update
by
WSlloydkuhnle
1 day, 19 hours ago -
TeleMessage, a modified Signal clone used by US government has been hacked
by
Alex5723
3 days, 20 hours ago -
The story of Windows Longhorn
by
Cybertooth
3 days, 7 hours ago -
Red x next to folder on OneDrive iPadOS
by
dmt_3904
3 days, 22 hours ago -
Are manuals extinct?
by
Susan Bradley
22 hours, 29 minutes ago -
Canonical ditching Sudo for Rust Sudo -rs starting with Ubuntu
by
Alex5723
4 days, 7 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.