How to import a macro file (previously exported as .bas file) to Microsoft Word using command line? - ms-word

I'm writing a command-line program that has a step in which I need to replace text in a Word file. The replacing task is accomplished using Word macro.
What I need to do now is to call this macro from command-line. At the moment we can do this by using the /mMacroName parameter of 'winword.exe', i.e. <path-to-msoffice>\winword.exe /mMacroName. But this needs the macro to be already available as a global macro.
Since I need to run the program on another computer, I need to import the above replacing macro programmatically... and I don't know how to do this.

Adding the macro using VBScript would be an option. You can find a sample to get started in the following related question:
Remove MS Word macro using VBScript

Related

How to find complete list of arguments to use WORD in CLI

I would like to know if it is possible to have all the arguments of the command / exe "winword".
In the official docs the are some examples:
https://support.microsoft.com/en-us/office/command-line-switches-for-microsoft-office-products-079164cd-4ef5-4178-b235-441737deb3a6
But there not all the commands, for example, there is "/mFilePrintDefault" or "/mFileExit"
The objective being to be able to print a pdf without user action.
The Macro Commands are going to vary from one version to the next and of course you can start with your own macro file or use an AutoMacro.
The examples you give are 2 from part of the "Fixed Commands"
There are three lists available but I have no idea which commands function in a specific version as a command line macro, you would need to try them out.
ECMA-376 Office Open XML File Formats [ECMA-376], Fixed commands are here https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/37bf80f7-1d74-47f6-8721-aa077cadca4d
ISO/IEC-29500 Office Open XML File Formats [ISO/IEC-29500:2012], Fixed commands are here
https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oi29500/1ecf33cf-3601-45f0-89fb-0ab824739343
And listed under Basic Types as https://learn.microsoft.com/en-us/openspecs/office_file_formats/ms-doc/e86aecb4-bb67-4de2-9b06-37771115f274
A common example to show using more than one command(s) in sequence is
"path to\winword.exe" "path and filename.docx" /q /n /mFilePrintDefault /mFileExit
But your default printer needs to be a PDF one otherwise your macro needs to more complex

How to pass arguments from UFT to command line

I am trying to run tests in UFT by running a .vbs file. I am also passing arguments through command line. .vbs file reads the arguments and sets the environment variable of UFT. Hence, I can read them inside UFT.
qtApp.Test.Environment.Value("First_Argument") = WScript.Arguments.Item(0)
qtApp.Test.Environment.Value("Second_Argument") = WScript.Arguments.Item(1)
After that, I want to get a number as an output from UFT because I will use that output to pass it to the next command in command line.
The Test Parameters Object can be a way , more detailed in the Automation Object Documentation
You will have to define the TestParameters of the TestCase from the UFT IDE(manually) there is no way to define them automatically. If you declare them as in and out type, and change their value as a part of a Test Case, you would be able to read it afterwards from the vbs (Do not open a new Test Case until you did not read out the preferred values)
Although this is a working (and standard) way for exchanging parameters between the driver script and the TA Robot(UFT) I would advise you to use a simple file based way of doing this - managing test parameters can be very time consuming.
Tell the script via an Environment variable the path of the xml / json or simple text file where you expect the results to be written and when the test is done, read the content of the file (assuming the test will write into that file)
The plain old file way should not be underestimated especially in such circumstances.

Custom batch file creation for building code generated from Simulink Models

How can I create a custom batch file for my code generated from Simulink model ?
I can see, if I edit and change my template make file from Configuration Parameter Dialog box, I can get the desired make file.
But I want a custom .bat file too, that calls this make file along with other commands.
I have some environment variable to set and run couple of scripts in .bat file, before compilation begins. Based on these outputs from script the code is to be compiled and linked.
Using Matlab Version: 2012b
Create a STF_wrap_make_cmd_hook that generates your desired modelname.bat file as shown in the example code
here (mathworks login necessary).
You will probably also need to write your own make_yourtarget.m file and edit the make command field shown in your screenshot to use that one instead of make_rtw.
Other hooks into the build process are described here, perhaps the 'before_make' will also be useful.

Checking the value of Macro

Let's say one file is compiled and is in running mode and it is using some macro.Is there any way to check what value of the macro that is being used by the file.
eg if the file contains
-define(TIMEOUT,200).
From terminal how can i check what TIMEOUT definition is being used by the file.
Why I want is because suppose file is in running mode and i changed the macro definition in between and forgot to compile the file. I want to confirm what defintion it is taking.
Macros do not survive even the earliest stages of the compilation as the preprocessor substitutes them immediately in the source. You will have to define and export a separate function to see their values, something like:
macro_values() ->
[{'TIMEOUT',?TIMEOUT},...].
You can then call this from the shell and get the values that were substituted.

How to save a document in ms word 2003 using command prompt?

Please help, How to save a document in ms word 2003 using command prompt?
The only thing I know about cmd is making a directory(mkdir), open ms word(win word), and hide rar files to jpeg files. And moving files from 1 directory to another.
You can open Word document from the command prompt (starting a new Word process), but there is no easy way of sending any commands to a runnning instance of Word by a simple command line script. If you want to save Word documents programmatically, you can, for example, use VBA ("macros") or VBScript for it. But it would make much more sense if you change the Word document programmatically before, so I suggest that you first make yourself comfortable with VBA.
AFAIK there's no direct way to send a command from command line to words UI. You have to imploy a tool or trick here:
Using an autostart macro was sufficient if you want to convert data like opening a txt or html file with the command line and save it as a doc file with the autostart macro. It may even work to shut word down again within that autostart macro.
Another possibility is a kind of Win-GUI-recorder like AutoIT. This can create scripts or exes containing a script that record some actions you have previously shown it yourself (and much much more). Take a look at their pages at http://www.autoitscript.com/autoit3/.
And a third possibility is Word's ActiveX-IF that can be acessed by any programming system (even AutoIT).
Greetings from Germany!
LuI