View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Accessing Word from Excel

Pikus,

Set a reference to the Word object library, then use something
like


Dim WordObj As Word.Application
Dim WordDoc As Word.Document
On Error Resume Next
Set WordObj = GetObject(, "Word.Application")
If WordObj Is Nothing Then
Set WordObj = CreateObject("Word.Application")
End If
On Error GoTo 0
If WordObj.Documents.Count = 0 Then
Set WordDoc = WordObj.Documents.Add
Else
Set WordDoc = WordObj.ActiveDocument
End If
WordObj.Selection.TypeText "Hello World"



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"pikus " wrote in message
...
I want to know more about creating a word document using VBA in

Excel.
So far I've come up with this:

Private Sub CommandButton1_Click()
Dim wrd As Word.Document
Application.ActivateMicrosoftApp (xlMicrosoftWord)
Set wrd = Word.Application.ActiveDocument
With Word.Application
wrd.Selection.TypeText "HI!"
End With
End Sub

But "ActiveX component can't create object" for this line:
Set wrd = Word.Application.ActiveDocument

Then I get "Object doesn't support this property or method" for

This
line:
wrd.Selection.TypeText "HI!"

Any help is greatly appreciated - Pikus


---
Message posted from http://www.ExcelForum.com/