VBA to detect a Word doc using a macro in normal.dot


I have a tool built in Access that scans spreadsheets and Word for macros. Is working OK, except for the case of a Word Doc that has a macro that is stored in normal.dot.

Is their any detectable flag/object (using VBA) that would indicate this?

LVL 23
Kelvin SparksAsked:
Who is Participating?
GrahamSkanConnect With a Mentor RetiredCommented:
Every document has an attached template.This is where any macros usually are. Less usually macros are in the document itself. The default template is the Normal template. Many users have macros there. Also there can be other global templates in the a user's Word Startup folder which contain macros. For this reason a document in one location can have access to macros that it doesn't have in another.

You can check  check the attached template property with


and test for global templates:

     For Each objAddIn In objWordApplication.AddIns
           MsgBox objAddIn.Name
      Next objAddIn

RobOwner (Aidellio)Commented:
with reference to http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_25879769.html

What happens when you run your script specifying the normal.dot file?

You could include a scan for normal.dot files in your Word CheckWordForMacro function.  It could scan the users profile template directory: %USERPROFILE%/Application Data/Microsoft/Templates for the normal.dot
I think you have to check word instance to exist with your machine.
if word = nothing then
      msgbox "Install MS Word in your machine
end if
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Kelvin SparksAuthor Commented:
We/re scanning remotely accross network shares. Won't have access to the local drives. More interested to know if there's something in a document that indicates that a template is/can be called.
RobOwner (Aidellio)Commented:
My understanding is that if you open a word document it will load the normal.dot template of the user that is running the tool.  So if you run this tool on your computer then it would load the normal.dot from your computer. Make sense?
Kelvin SparksAuthor Commented:
Yes, I think it does (and any user level macros in their normal.dot will be unavailable)
RobOwner (Aidellio)Commented:
If you have profile set up for each user in a active directory domain then it will copy the normal.dot with the rest of the Roaming profile to the server where you could scan it?
PandaPantsConnect With a Mentor Commented:
==>"...except for the case of a Word Doc that has a macro that is stored in normal.dot. "

A Word doc that has a macro that is stored in normal.dot doesn't actually have a macro in itself at all. A Word doc that doesn't have a specific Attached Template (see GrahamSkan's code, above) is attached to "normal.dot" by default, but that template will change depending on the user and the machine (except in the case of true Roaming Profiles, in which case it will stay with the user regardless of the machine).

It appears to me that your routine is working as designed. Normal.dot is loaded globally by default in Word, which means that any macros in Normal.dot are available to any documents that are open in that Word session. If you put another template containing macros in the Word startup folder, those macros will also be available to any document, exactly like those in Normal.dot.

I'm not convinced you actually have a problem, here.
Kelvin SparksAuthor Commented:
Than ks to all. Those last two have helped in my limited understand of Word immensely and tell me just what I need to know.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.