Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2013, 12:08 AM
jdockstader jdockstader is offline From the command line, how do I run a Word macro? Windows 7 64bit From the command line, how do I run a Word macro? Office 2007
Novice
From the command line, how do I run a Word macro?
 
Join Date: Feb 2013
Posts: 4
jdockstader is on a distinguished road
Default From the command line, how do I run a Word macro?

As part of a workflow in a PDM system, I have to convert a Word file to PDF. I've written a macro that will save the PDFs and close Word. I can't put that macro in every users Normal.dotm file so I need to be able to load it from a shell command. I saved my macro, SaveAsPDF, in a Custom.dotm and I can put that in a shared location (during testing it's on my c: drive)

When I execute the command
"C:\Program Files (x86)\Microsoft Office\Office12\winword" /l"C:\Custom.dotm" /w %filename% /mSaveAsPDF
Word opens with the file and the macro is present but doesn't execute.



I've tried using /t instead of /l to load the macro containing template but it doesn't seem to work at all.
Reply With Quote
  #2  
Old 02-03-2013, 01:32 AM
macropod's Avatar
macropod macropod is offline From the command line, how do I run a Word macro? Windows 7 64bit From the command line, how do I run a Word macro? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I believe your command-line would need to be:
"C:\Program Files (x86)\Microsoft Office\Office12\winword" /t"C:\Custom.dotm" %filename% /m"SaveAsPDF"
where 'C:\Custom.dotm' is the full path & filename of the template. Word templates are not usually stored in "C:\".
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-03-2013, 07:01 AM
jdockstader jdockstader is offline From the command line, how do I run a Word macro? Windows 7 64bit From the command line, how do I run a Word macro? Office 2007
Novice
From the command line, how do I run a Word macro?
 
Join Date: Feb 2013
Posts: 4
jdockstader is on a distinguished road
Default

Thanks for the response.
When I do
"C:\Program Files (x86)\Microsoft Office\Office12\winword" /t"C:\Custom.dotm" /w /q
Word opens up with a blank file and I can see the macro.

When I add the file I want to print
"C:\Program Files (x86)\Microsoft Office\Office12\winword" /t"C:\Custom.dotm" /w /q "C:\Users\jdockstader\Documents\10109 Router.docx"
Word opens up with the file but there are no macros.

When I do (switching from /m to /l)
"C:\Program Files (x86)\Microsoft Office\Office12\winword" /l"C:\Custom.dotm" /w /q "C:\Users\jdockstader\Documents\10109 Router.docx" /m"SaveAsPDF1"
Word opens up with the file and I can see the macro but it isn't executing.
Reply With Quote
  #4  
Old 02-03-2013, 02:52 PM
macropod's Avatar
macropod macropod is offline From the command line, how do I run a Word macro? Windows 7 64bit From the command line, how do I run a Word macro? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Is your "10109 Router.docx" document based on the "C:\Custom.dotm" template? If not, I suspect your '/m"SaveAsPDF1"' directive needs to tell Word needs to include the template name - possibly something along the lines of:
/m"C:\Custom.dotm.Module1.SaveAsPDF1"
where 'Module1' is the name of the code module in which the macro resides.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 02-03-2013, 10:41 PM
jdockstader jdockstader is offline From the command line, how do I run a Word macro? Windows 7 64bit From the command line, how do I run a Word macro? Office 2007
Novice
From the command line, how do I run a Word macro?
 
Join Date: Feb 2013
Posts: 4
jdockstader is on a distinguished road
Default

Correct that the macro isn't in the template used to create the files. I use the /l to get the file to open the template with the macro and the file but I wasn't able to identify the macro.

This seems to be a known problem with Word 95, 97 and 2000.
http://support.microsoft.com/kb/173505
http://support.microsoft.com/kb/181783
http://support.microsoft.com/kb/201932
but their suggested fix won't work for me

You'd think they'd have fixed it in the last 18 years. Guess it isn't exactly a common problem.
Reply With Quote
  #6  
Old 02-03-2013, 11:36 PM
macropod's Avatar
macropod macropod is offline From the command line, how do I run a Word macro? Windows 7 64bit From the command line, how do I run a Word macro? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It seems to me the simplest solution would be to add the macro to the document's template. Then you probably wouldn't even need to tell Word to load the template.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 02-04-2013, 04:51 AM
jdockstader jdockstader is offline From the command line, how do I run a Word macro? Windows 7 64bit From the command line, how do I run a Word macro? Office 2007
Novice
From the command line, how do I run a Word macro?
 
Join Date: Feb 2013
Posts: 4
jdockstader is on a distinguished road
Default

The problem I have us that these documents already exist and reside in a change controlled vault. I can't open them all up and add a macro to them. Also, the conversion to PDF will be done by a number of users so I can't add the macro to their Normal.dot. This would have allowed me to add the macro to the file and covert to PDF all at one time. I'll have to go back and see if I can output PDF in another fashion somewhere in the process. Thanks for your help.
Reply With Quote
  #8  
Old 02-04-2013, 06:09 AM
macropod's Avatar
macropod macropod is offline From the command line, how do I run a Word macro? Windows 7 64bit From the command line, how do I run a Word macro? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It doesn't matter that the documents already exist; what matters is that the macro should be in their templates. That means modifying only the relatively few templates concerned.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
command line, macro vba word

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
From the command line, how do I run a Word macro? Command line syntax for 2010 asearle Word 1 08-07-2012 05:42 AM
Word doc bug when closing from userform command button click macro Joe Patrick Word 1 07-05-2011 08:53 PM
Invoking a command line from inside Word bolpom Word 1 03-16-2011 03:03 AM
Command Line Argument xJediDadx Outlook 1 02-21-2011 03:47 PM
Command Line Switches Ringmaster Office 0 08-10-2010 06:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:27 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft