[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

programmatically produce Word docs

Posted on 2004-08-10
8
Medium Priority
?
490 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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

656 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