Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Accessing Word from Excel

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/

  #2   Report Post  
Posted to microsoft.public.excel.programming
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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Accessing Word from Excel

Thanks a million Chip. I promise only to use my powers for good.
Piku

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Accessing Word from Excel

This code is taken from the Samples.Xls file supplied with Excel 97.

Sub MS_Word()
Dim wd As Object
'Create a Microsoft Word session
Set wd = CreateObject("word.application")
'Copy the chart on the Chart Labels sheet
Worksheets("Chart Labels").ChartObjects(1).Chart.ChartArea.Copy
'Make document visible
wd.Visible = True
'Activate MS Word
AppActivate wd.Name
With wd
'Open a new document in Microsoft Word
.Documents.Add
'Insert a paragraph
.Selection.TypeParagraph
'Paste the chart
.Selection.PasteSpecial link:=True, DisplayAsIcon:=False,
Placement:=wdInLine
End With
Set wd = Nothing
End Sub

--
Regards
Andy Wiggins
www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"



"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/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Accessing Word from Excel

Thank you too Andy. This is great stuff. - Piku

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Excel pages using VB bob_mhc Excel Discussion (Misc queries) 1 July 16th 05 10:28 PM
Accessing Favorites in Excel 2003 Evan Setting up and Configuration of Excel 1 January 25th 05 10:27 PM
Accessing Outlook from Excel Chaplain Doug Excel Discussion (Misc queries) 0 December 19th 04 11:39 PM
How to stop Excel from accessing the net [email protected] Excel Programming 1 December 29th 03 04:20 PM
Accessing PowerPoint datalabels from excel VBA KD[_3_] Excel Programming 1 November 14th 03 04:36 PM


All times are GMT +1. The time now is 02:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"