Solved

programmatically produce Word docs

Posted on 2004-08-10
8
480 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
  • 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
 

Author Comment

by:arichexe
ID: 11768016
Language reference for commands such as ParagraphFormat.Alignment, InsertParagraphAfter, etc?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now