Solved

programmatically produce Word docs

Posted on 2004-08-10
8
485 Views
Last Modified: 2008-03-03
How can I utilize MS Word's exposed object model, and programmatically (using vbscript) produce Word docs?
0
Comment
Question by:arichexe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 3

Accepted Solution

by:
Sasho earned 125 total points
ID: 11767854
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
 

Author Comment

by:arichexe
ID: 11767938
Thanks!  How would I programmatically save the doc?  And, do you know of a good Word language reference guide?
0
 
LVL 3

Expert Comment

by:Sasho
ID: 11768008
You can use Wrddoc.Save

 What do you mean by Word language referance guide?
0
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!

 

Author Comment

by:arichexe
ID: 11768016
Language reference for commands such as ParagraphFormat.Alignment, InsertParagraphAfter, etc?
0
 
LVL 3

Expert Comment

by:Sasho
ID: 11768045
0
 
LVL 3

Expert Comment

by:Sasho
ID: 11768054
When I code OLE stuff I always have MSDN open and ready to look stuff up :)
0
 

Author Comment

by:arichexe
ID: 11768057
Thanks!  I tried WRDDOC.Save "c:\test.doc" and got a type mismatch error.
0
 
LVL 3

Expert Comment

by:Sasho
ID: 11768064
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question