• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

programmatically produce Word docs

How can I utilize MS Word's exposed object model, and programmatically (using vbscript) produce Word docs?
0
arichexe
Asked:
arichexe
  • 5
  • 3
1 Solution
 
SashoCommented:
Hey its very easy foll. these steps.
dim Oword as word.application
dim Wrddoc as word.document

On Error Resume Next
Set Oword = GetObject(, "word.application")

If Err.Number <> 0 Then
Set Oword = CreateObject("word.application")
Blnrunning = False
Oword.Visible = True
Else
Blnrunning = True
End If

AppActivate (Oword)

Set WRDDOC = Oword.Documents.Add

WRDDOC.Select

With Oword

.Selection.MoveDown

.Selection.InsertAfter ("SASHO")
.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Selection.Font.Name = "VERDANA"
.Selection.Font.Size = 9
.Selection.Font.Bold = True
.Selection.Font.Underline = True
.Selection.InsertParagraphAfter
.Selection.InsertParagraphAfter
.Selection.MoveDown

.Selection.InsertAfter (TNGstg) 'this can your variable to display
.Selection.Font.Name = "VERDANA"
.Selection.Font.Size = 9
.Selection.Font.Bold = False
.Selection.Font.Underline = False
.Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
.Selection.InsertParagraphAfter
.Selection.MoveDown

.Selection.InsertAfter <your variable here>
.Selection.Font.Name = "VERDANA"
.Selection.Font.Size = 9
.Selection.Font.Bold = False
.Selection.Font.Underline = False
.Selection.MoveRight
.Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
.Selection.InsertParagraphAfter
.Selection.MoveDown

.Selection.InsertAfter ("We take pleasure in placing our on your company for ")
.Selection.InsertAfter ("as detailed in this order. The conditions of this ")
.Selection.InsertAfter ("order are specified here under. ")
.Selection.InsertAfter ("Please quote this Order for payment and all future correspondence ")
.Selection.InsertAfter ("related to this order.")
.Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
.Selection.Font.Name = "VERDANA"
.Selection.Font.Size = 9
.Selection.Font.Bold = False
.Selection.InsertParagraphAfter
.Selection.InsertParagraphAfter
.Selection.MoveDown
end with

set oword=nothing
set wrddoc=nothing
This jus for your idea u can make any changes as u wish and as per your format. u can even work with the header and footer's and display as u like.
0
 
arichexeAuthor Commented:
Thanks!  How would I programmatically save the doc?  And, do you know of a good Word language reference guide?
0
 
SashoCommented:
You can use Wrddoc.Save

 What do you mean by Word language referance guide?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
arichexeAuthor Commented:
Language reference for commands such as ParagraphFormat.Alignment, InsertParagraphAfter, etc?
0
 
SashoCommented:
When I code OLE stuff I always have MSDN open and ready to look stuff up :)
0
 
arichexeAuthor Commented:
Thanks!  I tried WRDDOC.Save "c:\test.doc" and got a type mismatch error.
0
 
SashoCommented:
Use SaveAs instead if you want to give the name
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now