We help IT Professionals succeed at work.

How to create word-docs from command line

nmm
nmm asked
on
Medium Priority
236 Views
Last Modified: 2012-08-13
Hi

I want to force MS-Word to create a specific DOC-file from suartup:

I have a filename, say

"f:\test\worddocs\neudoc.doc",

folder "f:\test\worddocs\" exists, the file "f:\test\worddocs\neudoc.doc" not yet.

Now I want to start WINWORD so that it automatically create this file and show it for editing.

I tried:

>winword f:\test\worddocs\neudoc.doc

but it say "f:\test\worddocs\neudoc.doc" does not exist.

I tried

>winword /mFileNew("f:\test\worddocs\neudoc.doc")

but this is ignored by winword (it opens "Document1").

I try using my own Makro

sub creDoc(ByValue na as string)
 mydoc=documents.add
 with mydoc
   .SaveAs Filename=na
 end with
end sub

via

>winword /mcreDoc("f:\test\worddocs\neudoc.doc")


or

sub creDoc()
 na=command()
 mydoc=documents.add
 with mydoc
   .SaveAs Filename=na
 end with
end sub

via

>winword /mcreDoc f:\test\worddocs\neudoc.doc

but its ignored also.

Of course I could create a empty DOC in a special folder (say f:\prpareddocfiles\def.doc) and copy it to the file I want to create:

batch-file:

copy f:\prpareddocfiles\def.doc f:\test\worddocs\neudoc.doc
winword f:\test\worddocs\neudoc.doc

but this is not very nice.

nmm
Comment
Watch Question

bruintjeFreelance
CERTIFIED EXPERT
Top Expert 2006

Commented:
Hi nmm,

Saw this one two weeks ago had to comment then but it was lost again but here we go

-open your doc
-open the VB Editor
-insert a new module from the menu
-paste this code

Option Explicit

Public Sub CreateDoc()
  'MsgBox "testing this proc now"
  ActiveDocument.SaveAs "c:\test2.doc"
End Sub

-save and close
-run from the start box
winword /mCreateDoc c:\test.doc

HTH:O)Bruintje
bruintjeFreelance
CERTIFIED EXPERT
Top Expert 2006

Commented:
---------------------------
Hi nmm,

Any luck yet to try the suggestions in this thread?
Please provide some feedback to the experts willing to spend their time and try to solve your problem.

---------------------------
Thanks
:O)Bruintje
---------------------------
bruintjeFreelance
CERTIFIED EXPERT
Top Expert 2006

Commented:
---------------------------
Hi nmm,
 
Any update on this question?

in an effort to clean up old open questions

+----------------------------------------------------+
Your options are:

1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the
participants why you wish to do this, and allow for Expert response.  This choice will include a refund
to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information
outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with
details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
 --> Post comments for expert of your intention to delete and why
 --> You cannot delete a question with comments, special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below, include the question

QID/link. http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

Please click this Help Desk link for Member Guidelines, Member Agreement and the Question/Answer process:
Click you Member Profile to view your question history and keep them all current with updates as the
collaboration effort continues. http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
+----------------------------------------------------+


+----------------------------------------------------+
IMPORTANT #1
+----------------------------------------------------+
EXPERTS:    Please leave any comments regarding this question here on closing recommendations
if this item remains inactive another seven (7) days.
+----------------------------------------------------+


+----------------------------------------------------+
IMPORTANT #2
+----------------------------------------------------+
Bruintjes recommendation
-PAQ
-Points to Bruintje
+----------------------------------------------------+


---------------------------
Thanks
:O)Bruintje
---------------------------
nmm

Author

Commented:
Bruintje!
I tried your suggestion, but it does *NOT* work.

Your example creates, as I guessed at the first glance, everytime only

"c:\test2.doc"

no difference, which filname is passed to the commandline:

winword /mCreateDoc c:\test.doc
creates c:\test2.doc

winword /mCreateDoc c:\trynewfile.doc
creates c:\test2.doc too...


This was not what I'm looking for (cf. the original question!). I guess, "the time, you spend to solve the problem" where less the time you spend to send me long hints about my options to close the question.

So, up to now, I can not pass any points to you or anyone, because the question is still open.

May be it is impossible to do, what I want (of course you can write a VBS-script which will do the job, but this was also not the question).


Nevertheless, thanks for answering.





bruintjeFreelance
CERTIFIED EXPERT
Top Expert 2006

Commented:
glad i got you back on this one

stupid bruintje now i read that *answer* back again

you've to change the sub to

Option Explicit

Public Sub CreateDoc(Byval strName as string)
 ActiveDocument.SaveAs strName
End Sub

gonna test it now
Freelance
CERTIFIED EXPERT
Top Expert 2006
Commented:
well you're right about not doable starting a macro with parameter passing....

the reminder scripts are only reminders and when people not react i can't smell if things are solved or not, it's a weekly routine i run from scripts so at times i'm completely wrong

no need to pass the points, the question isn't answered that's all

Brian
nmm

Author

Commented:
Hi again,

the last 2 weeks I had to made several trips and could not read my mails. Today I read the reminders and got a little angry on it, sorry...

If it is actually impossible to create a DOC from command line, than this is also an answer, so I let the question open for 1 or 2 weeks and than I pass the points to you...

nmm


bruintjeFreelance
CERTIFIED EXPERT
Top Expert 2006

Commented:
Ok time to clean up

my recom will be
-PAQ
-refund points (problem was not solved)
-this will be finalized with no further update (29.06.2002)

PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER

HAGD:O)Bruintje
nmm

Author

Commented:
Sorry, weeks passed, and I miss to do, what I promised...
Sorry, what does "HAGD:O)" mean?
nmm

Explore More ContentExplore courses, solutions, and other research materials related to this topic.