RMTrak Visual Basic Run Time Error 4248 - vba

When attempting to run RMTrak (a requirements mapping software), Visual Basic runtime error 4248 would appear. This only happens on a single file in the set of files being used. Other errors occur when attempting to run RMTrak while the document is currently open.
Run-time error '4248':
This command is not available because no document is open.
- https://support.microsoft.com/en-us/kb/813983 (1/6/2017)
How RMTrak works: RMTrak will open a file, parse it for specific formats, and consolidate it to their viewer. It will use tags inputted into the documents to relate to other other requirements, input specs, etc to show a list of requirements, their mapping, and how it relates.

Open up the document in question and hit "Alt-F11". The VBA editor will appear. Either delete or comment out the VBA code. Save. Re-run.
When RMTrak is parsing the document, it is attempting to run the Visual Basic code that is embedded in the document. Since the document is not being opened by Word when RMTrak is parsing it, the "ActiveDocument" property is invalid.

Related

Can't remove reference to template

I have a macro-enabled Word document with a reference to a template in the Project > References section of the VBA/macro editor. I can't delete this reference directly. When I delete it through the Developer panel's Document Template dialog box, the template name in that dialog box reverts to Normal, but the macros' Project > References section still shows the old template.
Behavior: the macros fail with the message
"Compile error: can't find project or library."
The missing template appears to be the source of the complaint, since I can create a dummy file with the same name and location as the missing template and the macros load fine. VBA is not relying on any code in that missing template, either, from what I can see. It's just a missing file that's specifically referenced so the compiler chokes. But I need to circulate this macro-enabled document on its own without requiring users to make a new path and copy a dummy file into it.
I've tried editing the XML within the .docm file to remove the reference, but the template is also referenced in the vbaProject.bin binary file. Hex editing that binary file to remove the reference (replacing it with nulls or a valid path/name of the same length) and re-zipping the structure produced a document that Word recognized as corrupted (also tested re-zipping it without making any changes, to make sure the unzipping/zipping process wasn't causing new problems, and that version opened fine but failed at the same place it always fails: the missing template file). Word produced a recovered version, which shows all the macros listed, but it also shows the reference to the template I'm trying to remove.
Windows 10, Word 365 latest
Help?

How do I create a Word VBA personal VBA code library as I have done in Microsoft Excel..?

How do I create a Word VBA personal code library as I have done in Microsoft Excel..? I had this working, but today it broke and I cannot make it work again. I originally did this because my Normal.dot file blew up and I lost all my macros. I found a blog post that described how to do it, but I cannot find my way back there. I've Google this extensively, but not found a solution.
There are some twists & turns here, as described below...
In Microsoft Excel, one can easily create a "code library project". This is simply a standard XLSB file with VBA modules in it, saved in the ..\Excel\STARTUP folder alongside the PERSONAL.XLSB file.
When the VBA editor is open in any other XLSX/B file, the modules in the code library file are always visible. And thre's not a requirement to create a VBA project reference to see them. The library modules can be natively edited as if they were an integral part of any other file, without requiring the library file to be open in another window to do so, as shown in the picture...
However...in Microsoft Word, it seems to work differently, and...strangely. If the same is done: create a DOCM file with custom code modules, and save it in the ..\Word\Startup\ folder, those modules are not visible in the VBA Project Explorer.
Following along the chain of logic from Excel to Word, and do as others have done...save the DOCM as a DOTM instead, and save it in the ..\Templates folder with the Normal.dotm file. Still, it is not visible in Project Explorer.
It's not until Normal.dotm is opened for editing and the library DOTM is added as a VBA Project Reference that it finally appears in the Project Explorer, but only while Normal is open. Plus...it opens the code library file for editing in another window..! If Normal is saved with that reference, and a new document is created from it, the library code cannot be edited and displays the error "project is unviewable"...
It's not until the library DOTM file is opened for editing in a second window that it's code becomes editable, and it does so in all Word VBA windows on all documents at the same time.
There is one glimmer of hope: if I create a new blank DOC from the library DOTM instead of Normal.DOTM, it works..! Any document created from the library retains a link to the code modules there, including any new or edited ones, and they can be edited natively right there in the Project Explorer. And this includes the code modules in Normal.DOTM too.
It seems the "editability" is one way: documents created from any other template can see & edit both their own code and those in Normal.DOTM, but not the other way around: documents created from Normal.DOTM can only see their own code.
How can this connection be made two-way for all documents, regardless of what template they were created from..??
I've been trying to wrap my head around the possibility it may be a security/malware issue, but I can't come up with one. If macros are already enabled in the Trust settings, malware is already 99% on the way to controlling a machine anyways. The only step left is enabling VBIDE.
A very similar question on Microsoft Answers:
Is there a startup or template file in Words that allows one to store "personal macros", i.e. macros that one wants to have always available while editing documents (I am seeking the equivalent to the PERSONAL.XLSB file in Excel, where I can store macros that then are available in all sheets that I open).
And the solution given:
Word uses the default template Normal.dotm for this purpose. Macros stored in Normal.dotm will be available in all documents. Apart from that, Normal.dotm also serves as the default document template, and it also stores the user's formatted AutoCorrect entries.
Just like Personal.xlsb, Normal.dotm doesn't exist in a clean new installation, but it will be created when needed.
The location for Normal.dotm is
C:\Users\<username>\AppData\Roaming\Microsoft\Templates
AppData is a hidden folder, so you must display hidden files and folders in order to see it in Windows Explorer.
Similar questions (also on answers.microsoft.com) have been offered same type of solution.
Macros that should be globally available can be stored in Normal.dotm or in a template located in the Startup folder for Word. See also:
And:
In Word, personal settings (those that aren't stored in the Registry) are stored in the Normal template, Normal.dotm. When you change and save settings or create macros, they are automatically saved in Normal.dotm unless you choose to save them in another template. Normal.dotm is automatically loaded when you start Word, and new Blank Documents are based on Normal.dotm.

Word file corrupts after SaveAs

I've build a program to generate other docm files. The program works just fine without saving the generated files through VBA. When I do save through VBA with a SaveAs statement, however, the generated file becomes corrupt. Trying to open the file gives the following message:
"Could not open the file, there is a problem with the contents."
The SaveAs statement is as follows:
qDoc.SaveAs (getQuizURL(quizname))
The quizUrl function has been thoroughly tested and operates properly.
Does anyone know what's causing this and how to solve it? I could save it all manually, but given that other people will be using this program I'd like it to make it as friendly as possible.
You are missing file format specification.
I am not sure about SaveAs either from your code.
I have got Office -2016 and it has a function called SaveAs2, but may be SaveAs is available in older versions.
Anyhow, change your code to specify the file format.
ThisDocument.SaveAs2 "C:\temp\Test.docm", WdSaveFormat.wdFormatXMLDocumentMacroEnabled
This will do the trick.

Have PDF-Creator suppress warning dialog not to halt build process

I have a msbuild script that includes creation of a few PDF's using PDF creator. It's the Convert2PDF.vbs that's being used, converting doc's to PDF's, and a while ago it stopped working and none seemed to take the time to fix it. So I looked into it and by debugging the script I found that it was in fact a document for which Word presented a dialog with information about contents being larger than the margins. This halted the entire thing since none could press this dialog during the auto-build.
So what I wonder is if there is a way to tell the PDF Creator script, via cmd line arguments or by altering the script, to suppress these kinds of warnings and just continue with conversion?
I solved this by creating a script in word that suppressed warnings if the given document resided within the build folder specified.

Unable to open word file (MSWord 2007) when word automation program is running

In my application i am using word automation to get the text content from the file. It is working fine no issues. But at the instant when word automation is processing, if i open the word file, it is throwing a dialog with message (any file)
"This file is in use by another application or user.
(C:\User\xyz\AppData...\Normal.dotm)".
When I am closing the dialog, it is asking for save the file "normal.dotm"...template file.
This happens only in MSWord 2007 not in MSWord 2003. can any one tell the solution please.
This probably happens because one Word instance has locked Normal.dotm and your instance modifies it and tries to save it.
You can try to set the Saved property of your template to True. Try this: Application.NormalTemplate.Saved := True. Word will now think that changes to Normal.dotm are saved and should not try to save again.