?
Solved

programmatically produce Word docs

Posted on 2004-08-10
8
Medium Priority
?
488 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 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:arichexe
ID: 11768016
Language reference for commands such as ParagraphFormat.Alignment, InsertParagraphAfter, etc?
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 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