Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-09-2012, 06:35 AM
tinfanide tinfanide is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Expert
Losing VBA codes in .dotm
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Losing VBA codes in .dotm

I've a dotm file and add some codes.


Since I cannot upload a dotm file here, I have attached it in
http://www.box.com/s/4b7c859d87c60f20c609

Code:
Private Sub Document_Open()
MsgBox "open"
End Sub
But it does not trigger the codes.
Reply With Quote
  #2  
Old 04-09-2012, 07:14 AM
tinfanide tinfanide is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Expert
Losing VBA codes in .dotm
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default How do I save VBA codes in .dotm files?

Quote:
Originally Posted by tinfanide View Post
I've a dotm file and add some codes.
Since I cannot upload a dotm file here, I have attached it in
http://www.box.com/s/4b7c859d87c60f20c609


Code:
Private Sub Document_Open()
MsgBox "open"
End Sub
But it does not trigger the codes.

Source:
http://www.box.com/s/4b7c859d87c60f20c609

Please take a look at the demo of the problem:

Demo:
http://youtu.be/scWAD2-heKg


Well, I've found that
the codes written there are run when I open a .docx file.
By then, I know how it works.
It works for a normal document (.doc, .docx).
It does not work for a template (.dotm).

But another question comes:
How do I save VBA codes in .dotm files?
Reply With Quote
  #3  
Old 04-09-2012, 03:43 PM
macropod's Avatar
macropod macropod is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi tinfanide,

If you want the macro to fire when you create a new document from the template, you need a Document_New macro. All it needs to do is to call your Document_Open macro. However, as your template doesn't have a table, the macro will throw an error. That will also happen to the new document once it's been saved without a table. And, if you add a properly-formatted table to the template, you won't need the Document_New macro.

PS: You can attach dotm files, etc by converting them to zip archives first.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 04-09-2012, 07:43 PM
tinfanide tinfanide is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Expert
Losing VBA codes in .dotm
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Well, thanks for the second point about converting files to zips.

But for the first point,
What I meant was

1. Create a .dotm file
2. Open the .dotm file (itself) (right-click the file, click "Open")
3. Go to VBE
4. Under the Project panel, in the TemplateProject section, enter some codes whatever
5. Save the .dotm file
6. Close the .dotm file
7. Open the .dotm file (itself) again (right-click the file, click "Open")
8. Go to VBE
9. The codes disappear

I don't know why the codes have disappeared.
Reply With Quote
  #5  
Old 04-09-2012, 07:58 PM
macropod's Avatar
macropod macropod is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi tinfanide,

I did as you suggested and found that the changes were, in fact, retained in the saved template. Are you sure you're making them in the template and not somewhere else?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 04-09-2012, 08:33 PM
tinfanide tinfanide is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Expert
Losing VBA codes in .dotm
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Hi tinfanide,

I did as you suggested and found that the changes were, in fact, retained in the saved template. Are you sure you're making them in the template and not somewhere else?
Yes,
I want the codes to stay in the .dotm file itself,
not save the codes in the Normal section where it influences all the documents on my machine.
Reply With Quote
  #7  
Old 04-10-2012, 12:56 AM
macropod's Avatar
macropod macropod is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As I said:
Quote:
I did as you suggested and found that the changes were, in fact, retained in the saved template.
If the changes are not saving for you, that suggests you either made the changes somewhere else or you didn't save them. Did Word prompt you to save changes when closing just the template?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 04-10-2012, 01:31 AM
tinfanide tinfanide is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Expert
Losing VBA codes in .dotm
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
As I said:

If the changes are not saving for you, that suggests you either made the changes somewhere else or you didn't save them. Did Word prompt you to save changes when closing just the template?
1. where I save the codes;

Not in the Normal section

2. whether Word prompts me to save the Macro-enabled template file;

No, It does not.

Please watch this:
http://youtu.be/svxIyGxPXmA
Reply With Quote
  #9  
Old 04-10-2012, 01:45 AM
macropod's Avatar
macropod macropod is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi tinfanide,

It certainly looks to me like you're adding the code to a document (not a template). How do I know? Simply: the vba project you're adding the code to says 'Project (Doc1)', but when you (re)open the template, then open the vbe, it says 'TemplateProject (Doc1)'!
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 04-10-2012, 01:51 AM
tinfanide tinfanide is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Expert
Losing VBA codes in .dotm
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Yes, ya've got the point.
But this time I right-click open the template (doc1.dotm) and go to VBE
Yes, it is 'TemplateProject (Doc1)'
But again I add codes to this section and save the .dotm file
Next I right-click it,
The codes disappear again under 'TemplateProject (Doc1)'.
Could ya tell me why?
Reply With Quote
  #11  
Old 04-10-2012, 01:59 AM
macropod's Avatar
macropod macropod is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi tinfanide,

I can't reproduce the problem by editing the template so, if that's what you're doing now, I can't tell you why you're having problems with it.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 04-10-2012, 02:45 AM
tinfanide tinfanide is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Expert
Losing VBA codes in .dotm
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

I should say I've tested by saving the same codes under the Project (Document) (not the Normal one) in both

xlsm
doc

xlsm
ok (after saving, re-open it and see the codes there)

doc
not ok (same problem like dotm / dotx)

It seems that there is some problem with my Office Word.
Reply With Quote
  #13  
Old 04-10-2012, 03:05 AM
macropod's Avatar
macropod macropod is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Have you tried repairing Word? You do this via 'Programs & Features' in the Windows Control Panel.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 04-11-2012, 03:05 AM
tinfanide tinfanide is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Expert
Losing VBA codes in .dotm
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Have you tried repairing Word? You do this via 'Programs & Features' in the Windows Control Panel.
Repairing doesn't work at all.
I even went to %APPDATA%\Roaming\Microsoft\Office...
and deleted all the files there, including those under template
It didn't work, either.

I turned to the last resort then - reinstall Win7.
It worked, but it was hassle. Doesn't seem, uh... not sensible. Turning the OS over for a program in the OS...

I still don't know where it got wrong,
maybe registry... just a guess...
As a novice user of the Windows OS, the best I could say, every time when there's a problem (strange problem) and I couldn't google a solution, I would say there's something to do with the Registry.

But thanks for your follow-up.
Reply With Quote
  #15  
Old 04-11-2012, 03:14 AM
macropod's Avatar
macropod macropod is offline Losing VBA codes in .dotm Windows 7 64bit Losing VBA codes in .dotm Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi tinfanide,

FWIW, there were additional steps that could have been taken before resorting to a system reinstallation. See, for example:
http://support.microsoft.com/kb/921541, http://support.microsoft.com/kb/925175
http://word.mvps.org/FAQs/AppErrors/...artingWord.htm

That said, I'll admit it is possible the problem was a more deep-seated Windows one that could only be solved by working on the OS itself.

Glad you've got it sorted.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
dotm



Similar Threads
Thread Thread Starter Forum Replies Last Post
Losing VBA codes in .dotm New template/New normal.dotm kenglade Word 3 12-19-2011 04:00 PM
Losing VBA codes in .dotm How to get to normal.dotm Aiken_Bob Word 4 05-02-2011 02:41 PM
How to use .dotm template extension in MS Word? dude444 Word 0 09-20-2010 09:34 AM
template dotm unable to load in word 2003 dude444 Word 0 09-16-2010 02:13 PM
Losing VBA codes in .dotm Word 2007 crashes due to corrupt normal.dotm stevebond001 Word 1 05-11-2010 10:49 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:13 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft