Page 1 of 2 12>
Topic Options
#102102 - 2003-06-13 04:34 PM Open a created word doc, with a template...
cmarti Offline
Hey THIS is FUN

Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
I'm in the process of taking one large file, breaking it up into smaller files based on userid, and pulling each broken file into a template and saving it. I've finished the part where the file is broken based on userid, and I have a template. I can't seem to open word,with an already created document and use a specified template (miscinfo.dot). I've tried the following:
code:
 
"c:\Program Files\Microsoft Office\Office10\winword.exe" /t"E:\miscinfo.dot"

code:
"e:\invoices\miscinfo\mydoc.doc" /t"E:\MiscInfo.dot"

The first opens word with the template, the second opens the doc, but not the template...

Help. [Frown]

Top
#102103 - 2003-06-13 04:43 PM Re: Open a created word doc, with a template...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
what about opening word with the template, write the data in and save as?

that is easiest way as I see it.
where is the original data?
in text or in some office document?
_________________________
!

download KiXnet

Top
#102104 - 2003-06-13 04:48 PM Re: Open a created word doc, with a template...
cmarti Offline
Hey THIS is FUN

Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
Thanks for the QUICK response!!! [Big Grin]

The original data is in the main file, although I am able to pull it out and push it into a text file. How would I do an open and save as through kix?

Top
#102105 - 2003-06-13 04:53 PM Re: Open a created word doc, with a template...
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
there are some posts in the COM forum using WORD and Excel... that would be the way to go.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#102106 - 2003-06-13 04:56 PM Re: Open a created word doc, with a template...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it's rather big thing for me to just pull it out of my head here, but...
you would connect to word via createobject("microsoft.word")
that way you can control word in normal script.

what the commands/functions you need are descriped in words vbscripting part of manual.

or even open a word, do a macro that does the job and then just translate it to kix (the board can help in that)...

the macro path is easier that it does not require many hours of searching.
_________________________
!

download KiXnet

Top
#102107 - 2003-06-13 04:59 PM Re: Open a created word doc, with a template...
cmarti Offline
Hey THIS is FUN

Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
Rad,
Thanks for the info, I was searching in the scripts, and starters forums so I didn't find anything. I do see many posts in the com forum.

Lonkero,
Thanks, I will see exactly what the macro in my document does and try to write kix code from that.

[Big Grin] L8tr...

Top
#102108 - 2003-06-13 05:03 PM Re: Open a created word doc, with a template...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Was just farting with those command-line switches and think maybe this is the ticket ... macro's seem to come through ok:

winword /lc:\doc1.dot test.kix

Top
#102109 - 2003-06-13 05:09 PM Re: Open a created word doc, with a template...
cmarti Offline
Hey THIS is FUN

Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
Shawn, thanks for the suggestion...I tried that, and it didn't open the template, but it opened the file..
Top
#102110 - 2003-06-13 05:14 PM Re: Open a created word doc, with a template...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
yeah, i saw same but if you got to "templates and addins" does the template show as loaded ?

[edit]

Heres the link I found:

The link I found

[ 13. June 2003, 17:16: Message edited by: Shawn ]

Top
#102111 - 2003-06-13 05:17 PM Re: Open a created word doc, with a template...
cmarti Offline
Hey THIS is FUN

Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
Yes, the template does show as being loaded, but why can't I see it?
Top
#102112 - 2003-06-13 05:18 PM Re: Open a created word doc, with a template...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Thats the million dollar question my friend. I have no idea [Frown]
Top
#102113 - 2003-06-13 05:21 PM Re: Open a created word doc, with a template...
cmarti Offline
Hey THIS is FUN

Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
It's good that it loads, but not good that you can't see it... [Smile] Back to the drawing board...oh yeah, by the way, kixforms rocks!!
Top
#102114 - 2003-06-13 06:59 PM Re: Open a created word doc, with a template...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
no wonder this does not work if you try to rock with kixforms when coding word-centred kix [Big Grin]
_________________________
!

download KiXnet

Top
#102115 - 2003-06-13 08:17 PM Re: Open a created word doc, with a template...
cmarti Offline
Hey THIS is FUN

Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
hehehehehehehe..... [Big Grin]
Top
#102116 - 2003-06-13 08:51 PM Re: Open a created word doc, with a template...
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
cmarti

Maybe you can use this.

The following code will attach the template: E:\MiscInfo.dot
to the document: E:\invoices\miscinfo\mydoc.doc
using the function: ChangeTemplate()

Some strange things to observe:
- The document can be protected and the attached template is stil changed.
- BUT the template you attach may not be protected ???

So if the template is protected you must unprotect it before running the script, and protect it again when you are finished.

code:
Break On

ChangeTemplate("E:\invoices\miscinfo\mydoc.doc","E:\MiscInfo.dot")

Function ChangeTemplate($Document,$Template)
Dim $oWord
$oWord = CreateObject('Word.Application')
$RC = $oWord.Documents.Open($Document)
$oWord.ActiveDocument.AttachedTemplate = $Template
$oWord.ActiveDocument.Save
$oWord.Application.Quit(0)
EndFunction

-Erik

[ 13. June 2003, 21:15: Message edited by: kholm ]

Top
#102117 - 2003-06-13 09:22 PM Re: Open a created word doc, with a template...
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Nice try Erik but did not work for me.

Maybe cmarti will have better luck with it.

Microsoft Knowledge Base Article - 210565
Word Startup (Command-Line) Switches and Their Purpose
http://support.microsoft.com/default.aspx?scid=kb;EN-US;210565

What you should be able to do is open the document, then select all, copy, open template, paste, save-as %n%.doc

Top
#102118 - 2003-06-13 09:39 PM Re: Open a created word doc, with a template...
cmarti Offline
Hey THIS is FUN

Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
NTDoc,
Thanks for the path, I've actually already looked at that kb article. I can open word, it just doesn't open the template.

Kholm,
I'll try your code and see how it works for me.

The response from this board is always great...

Thanks.. [Big Grin]

Top
#102119 - 2003-06-13 09:49 PM Re: Open a created word doc, with a template...
cmarti Offline
Hey THIS is FUN

Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
Kholm,
The code opened the document, but it didn't change the template....

Top
#102120 - 2003-06-13 09:53 PM Re: Open a created word doc, with a template...
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Yeah.. cmarti, in general a Template is not really used this way. A Template is used as a basis or starting point to create a document.

That is why I think you will have to use VBA as in Erik's example to open the document, copy the contents, open the Template and paste the text into the Template, then when you save the file, it will automatically be saved as a .DOC

Top
#102121 - 2003-06-13 11:01 PM Re: Open a created word doc, with a template...
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
cmarti,

This code is VERY close to working. Not quite, but close.

What I "think" is happening is that the DOC1.DOC is open, copies data,
but then never switches to the .DOT
Then does a Save-AS to DOC4.DOC from DOC1.DOC

Maybe someone else can work on it with you. I don't have any more time
today to look at it.

code:
break on
ChangeTemplate("C:\Temp\test1.doc","C:\Temp\miscinfo.dot")
Function ChangeTemplate($Document,$Template)
Dim $oWord
$oWord = CreateObject('Word.Application')
$RC = $oWord.Documents.Open($Template)
$RC = $oWord.Documents.Open($Document)
$oWord.Selection.WholeStory
$oWord.Selection.Copy
$oWord.ActiveDocument = $Template
$oWord.Selection.PasteAndFormat("wdPasteDefault")
$oWord.ChangeFileOpenDirectory("C:\temp\")
$oWord.ActiveDocument.SaveAs("Doc4.doc", 0)
$oWord.Application.Quit(0)
EndFunction


Top
Page 1 of 2 12>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 483 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.071 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org