Posts: 97
Threads: 48
Joined: Sep 2010
Hi All,
Is it possible to create a word document with a filename? I like to create a filename like this: is search for a value (string) which contains eg. 99-88-65 and add something like "document" after it, so the word document had to be named: string_document and this will be as the example: 99-88-65_document
Further in the macro i would like to check if this document is open and continue with it.
Can this be done?
And please help me with an example if it's possible
Greetings
Sonic
Posts: 12,090
Threads: 142
Joined: Dec 2002
Where to search? If it is a string or a list of strings, please post it.
Posts: 97
Threads: 48
Joined: Sep 2010
Hi,
I extract this from another program.
So i have the sting called unique with the data i mentioned.
Grz
Posts: 12,090
Threads: 142
Joined: Dec 2002
Macro
Macro1991
str unique="99-88-65"
str fileName=F"{unique}_document.doc"
int w=win(F"{fileName} - Microsoft Word" "OpusApp" "" 1)
if w
,out "yes"
else
,out "no"
Posts: 97
Threads: 48
Joined: Sep 2010
Thanks,
one more question if i may....
If the document hasn't that name, how to give it that name? So Word sets the filename to the active document?
TIA
Posts: 12,090
Threads: 142
Joined: Dec 2002
Macro
Macro1991
;/exe 1
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
str unique="99-88-65"
str fileName=F"{unique}_document.doc"
int w=win(F"{fileName} - Microsoft Word" "OpusApp" "" 1)
if w
,out "yes"
else
,out "no"
,run "WINWORD.EXE" "" "" "" 0x800 win(" - Microsoft Word" "OpusApp") w
,Word.Application app._getactive
,VARIANT v=_s.expandpath(F"$documents$\{fileName}")
,app.ActiveDocument.SaveAs(v)
Posts: 12,090
Threads: 142
Joined: Dec 2002
if problems with type library
Macro
Macro1991
;/exe 1
str unique="99-88-65"
str fileName=F"{unique}_document.doc"
int w=win(F"{fileName} - Microsoft Word" "OpusApp" "" 1)
if w
,out "yes"
else
,out "no"
,run "WINWORD.EXE" "" "" "" 0x800 win(" - Microsoft Word" "OpusApp") w
,IDispatch app._getactive("Word.Application")
,VARIANT v=_s.expandpath(F"$documents$\{fileName}")
,app.ActiveDocument.SaveAs(v)
Posts: 97
Threads: 48
Joined: Sep 2010
Posts: 97
Threads: 48
Joined: Sep 2010
But i tested the first macro,
When an empty document was created, it correctly says it doesn't exist and gives the filename.
The second time with the same document (which was named) it also say's the document is not found?
Am i doing something wrong or is the check not correct?
Sonic
Posts: 12,090
Threads: 142
Joined: Dec 2002
With win, window name and class may be different in your Word version.
Posts: 97
Threads: 48
Joined: Sep 2010
When i search for the active window it says:
win("99-88-65_document - Microsoft Word" "OpusApp")
Posts: 12,090
Threads: 142
Joined: Dec 2002
My Word adds .doc in window name, maybe because Windows Explorer is set to show file extensons.