Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing To A Word Document 2

Status
Not open for further replies.

ndalli

Programmer
Nov 6, 1999
76
MT
HI,<br>
<br>
I need create a new Word Document and then write to it statements using different fonts and other type of formatting. All this should be done transparent to the user.<br>
<br>
Does anybody have an idea of how this could be done?<br>
<br>
Thanks in Advance
 
Did you look at SendKeys or DDE links <p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
I assume you want to do this from VB 5 or 6. <br>
Make sure to add the MS Word object library to your references. <br>
<br>
With the object library included, you should be able to add text and manipulate formatting as if you were in the Word. <br>
<br>
Here is an example:<br>
<br>
Option Explicit<br>
<br>
Dim wdApp As Object<br>
Dim wdDoc As Object<br>
<br>
Private Sub main()<br>
Set wdApp = CreateObject(&quot;Word.Application&quot;)<br>
wdApp.Visible = False 'this will keep word hidden<br>
<br>
Set wdDoc = wdApp.Documents.Add<br>
<br>
With wdApp.Selection<br>
.TypeText Text:=&quot;This is normal text&quot;<br>
.TypeParagraph<br>
.Font.Bold = wdToggle<br>
.TypeText Text:=&quot;This is bold text&quot;<br>
.TypeParagraph<br>
.Font.Italic = wdToggle<br>
.Font.Bold = wdToggle<br>
.TypeText Text:=&quot;This is italic&quot;<br>
.TypeParagraph<br>
.Font.Italic = wdToggle<br>
.Font.Name = &quot;Arial&quot;<br>
.Font.Size = 14<br>
.TypeText Text:=&quot;This is Arial 14 instead of Times 12&quot;<br>
.TypeParagraph<br>
End With<br>
<br>
wdDoc.SaveAs FileName:=&quot;D:\temp\Sample.doc&quot;<br>
<br>
wdApp.Quit ' When you finish, use the Quit method to close<br>
Set wdDoc = Nothing<br>
Set wdApp = Nothing<br>
End<br>
End Sub<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top