by Mofi » Thu Apr 01, 2010 12:29 am
Microsoft Word documents are binary files (or XML and other files in ZIP archives) and therefore can contain hidden data like Visual Basic code. Text files cannot contain hidden data. So it is not possible to save data like macro code, formatting styles, etc. together with the file itself.
You can only design your macro executed on every file open to do something only for a specified file. You have to include your macro code in
IfNameIs "name of the file without path and file extension"
your macro code
EndIf
Alternatively there is
IfExtIs "file extension without point"
your macro code
EndIf
Another method is that the file on which the macro should run has as first character (= top of file) a character which normally (never) exists at top of any other file, for example character × (that is not a lower case X, that is the multiplication X) and your macro starts with
IfCharIs "×"
your macro code
EndIf
Last suggestion: Your macro first searches for a string existing only in this file and when it is found, it sets the cursor back to top of the file and runs the macro code.
UnixReOff
Find MatchCase "unique document string"
IfNotFound
ExitMacro
EndIf
your macro code
This method has the disadvantage that it runs the search from top to bottom of every file making all file loads slower, especially for large and huge files.
Unfortunately for macros it is not possible to evaluate the full file name. Scripts can do that, but not macros, not directly. The command CopyFilePath can be used to copy the full name of the active file into a clipboard (best clipboard 9), but for evaluating it for example which a search it must be inserted into the file and then a search upward is used to evaluate if this is the file on which the macro should run. This method modifies all files on which this macro is executed even when deleting the inserted file name after evaluation and therefore it is not really good practice.