austenr
07-07-2005, 11:40 AM
This is a strange problem. I am trying to run the code below from the menu on the worksheet. If I do it that way it errors out on the .Documents.Add line. However, if you stay in the VBE and step through it using F8 it works.
Option Explicit
Sub CopyTableToAnyWordDocument()
Dim wdApp As Word.Application
ThisWorkbook.Sheets("Table").Range("A1:B6").Copy
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If wdApp Is Nothing Then
Set wdApp = GetObject(" ", "Word.Application")
End If
On Error GoTo 0
With wdApp
.Documents.Add
.Visible = True
End With
With wdApp.Selection
.EndKey Unit:=wdStory
.TypeParagraph
.Paste
End With
Set wdApp = Nothing
End Sub
I have attached the workbook also. :dunno
Option Explicit
Sub CopyTableToAnyWordDocument()
Dim wdApp As Word.Application
ThisWorkbook.Sheets("Table").Range("A1:B6").Copy
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If wdApp Is Nothing Then
Set wdApp = GetObject(" ", "Word.Application")
End If
On Error GoTo 0
With wdApp
.Documents.Add
.Visible = True
End With
With wdApp.Selection
.EndKey Unit:=wdStory
.TypeParagraph
.Paste
End With
Set wdApp = Nothing
End Sub
I have attached the workbook also. :dunno