newbee2
Technical User
- Apr 21, 2002
- 85
Hi,
I want to take a range from an excel sheet and paste it to a new word document laid out in landscape. I am using the following. I can get word to open but no document shows.
Case Is = 8
MsgBox "it works", vbOKOnly
Set rng7 = Sheet1.Range("a130:g154"
ThisWorkbook.Sheets(1).ActiveRange.Copy
WordStart
Sub WordStart()
On Error Resume Next
'create a word instance to use for the Table uses
'the existing word instance if there is one, otherwise creates
'a new instance.
Dim objWord As Object
Dim fisWordRunning As Boolean
Set objWord = GetObject(, "Word.Application"
If Err.Number = 429 Then
fisWordRunning = False
'word is not running; create a Word object
Set objWord = CreateObject("Word.Application"
Err.Clear
Else
'use current word object
fisWordRunning = True
End If
With objWord
'add new document
.Documents Add
.Documents.PageSetup.Orientation = wdOrientLandscape
'make word visible
.Visible = True
End With
With objWord.Selection
.EndKey Unit:=wdStory
'Paste Range
.Paste
End With
'release object Variable
Set objWord = Nothing
End Sub
Where be I going wrong
Regards
Bill
I want to take a range from an excel sheet and paste it to a new word document laid out in landscape. I am using the following. I can get word to open but no document shows.
Case Is = 8
MsgBox "it works", vbOKOnly
Set rng7 = Sheet1.Range("a130:g154"
ThisWorkbook.Sheets(1).ActiveRange.Copy
WordStart
Sub WordStart()
On Error Resume Next
'create a word instance to use for the Table uses
'the existing word instance if there is one, otherwise creates
'a new instance.
Dim objWord As Object
Dim fisWordRunning As Boolean
Set objWord = GetObject(, "Word.Application"
If Err.Number = 429 Then
fisWordRunning = False
'word is not running; create a Word object
Set objWord = CreateObject("Word.Application"
Err.Clear
Else
'use current word object
fisWordRunning = True
End If
With objWord
'add new document
.Documents Add
.Documents.PageSetup.Orientation = wdOrientLandscape
'make word visible
.Visible = True
End With
With objWord.Selection
.EndKey Unit:=wdStory
'Paste Range
.Paste
End With
'release object Variable
Set objWord = Nothing
End Sub
Where be I going wrong
Regards
Bill