#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
How do I save VBA codes in .dotm files?
Quote:
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? |
#3
|
||||
|
||||
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] |
#4
|
|||
|
|||
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. |
#5
|
||||
|
||||
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] |
#6
|
|||
|
|||
Quote:
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. |
#7
|
||||
|
||||
As I said:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
Quote:
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 |
#9
|
||||
|
||||
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] |
#10
|
|||
|
|||
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? |
#11
|
||||
|
||||
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] |
#12
|
|||
|
|||
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. |
#13
|
||||
|
||||
Have you tried repairing Word? You do this via 'Programs & Features' in the Windows Control Panel.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#14
|
|||
|
|||
Quote:
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. |
#15
|
||||
|
||||
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] |
Tags |
dotm |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
New template/New normal.dotm | kenglade | Word | 3 | 12-19-2011 04:00 PM |
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 |
Word 2007 crashes due to corrupt normal.dotm | stevebond001 | Word | 1 | 05-11-2010 10:49 AM |