How do I use Word and script to produce a document.

S

Sandy

I need to produce a dynamic document using word and conditional statements or
scripting. Any assistance is greatly appreciative.
 
D

Doug Robbins - Word MVP

You will have to give more information than that to receive any useful
assistance.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Sandy

Is it possible in word to add script!!!!!!!!!! I have not done this in
word!!!!!!!!!!

In word what is the syntax of a conditional if statement conditional on two
variables.

ie: if state = "fl' and contract = 'equity"
 
T

Tony Jollans

1. Yes. Press Alt+F11 to open the Visual Basic Editor.

2. Almost. if state = "fl" and contract = "equity" THEN
 
S

Sandy

Doug I need a general idea of how word and script work. I am already a
programmer. I have not done script thou. I just need to know if I pass two
variables from another application to a script word document will this work.
Or, do I need some kind of event to run. Based on this info I need to write a
case statement or if then else statement. I need to know how I could run the
script from word. I just need info on how to get started.
 
T

Tony Jollans

Word uses Visual Basic for Applications (VBA) - effectively a variant of VB
designed to run inside a parent application. From VBA you have access to the
Word object model and that allows the code to interact with documents (and
users and the environment). You can code VBA in the Visual Basic Editor
(VBE) accessible via Alt+F11 from Word.

Are you invoking Word from 'another application' (in which case, OK) or are
you wanting to communicate with an existing running instance of Word (not so
easy)?
 
S

Sandy

I am invoking word from another application.

Could you help in getting me started.

Purpose is to print dynamic titles for this document.

For ex: I will be given one variables 1) Contract Type
Based on the contract type print the required titles

Example of Contract Type: Equity, Straight Conversion, Upgrade Conversion.

------------------------------------------------------------
Titles:
Contract Type: Equity

Company
Join Us
Equity
-------------------------------------------------

Titles:
Contract Type: Upgrade Conversion

Company
Join Us
Upgrade Conversion

------------------------------------------------------

Titles:
Contract Type: Straight Conversion

Company
Join Us
Straight Conversion
 
T

Tony Jollans

You don't say what application or language you are using so it's difficult
for me to say how you should do it or whether you should do it in Word
(fired from your app) or direct from your app.

The basic idea is

Set WordAppPointer = CreateObject("Word.Application")
WordAppPointer.Documents.Open("name of document")
WordAppPointer.Run "NameOfMacroInWord", "ParameterToMacro"

Then in the Word Macro build up the document as you wish.
 
S

Sandy

What is the difference with what you wrote

Set WordAppPointer = CreateObject("Word.Application")
WordAppPointer.Documents.Open("name of document")
WordAppPointer.Run "NameOfMacroInWord", "ParameterToMacro

and with what I found on google


Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("U:\My Documents\CCSI\Contract
Document\Contract Template.doc")
 
I

Ishai Sagi

his code opens a document and then runs a macro that is in the
document.
what you found only opens a document.

both are viable options to what you are attempting to do (open a
document and change it). you can also use
"WordAppPointer.Documents.add" to create a new document instead of
opening an existing one.

If you have office 2003 or above, I guess what you should consider is
creating an XML schema for your document, create a template based on
that schema, and using the code, creating a new document based on that
template, and populating the xml nodes with the information from your
application.

What do you say?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top