E
Ed from AZ
With Word and Excel 2003 - I am trying to automate setting a range of
Excel cells into a Word bookmark as a table. I used the code below.
The code ran all the way through - but absolutely nothing showed up in
Word!!
Help??!?
Ed
Sub XLtoWord()
Dim wd As Object 'Word.Application
Dim doc As Object 'Word.Document
Dim wkb As Workbook 'This workbook
Dim wks As Worksheet 'This workbook
Dim rng As Range 'This workbook
Dim x As Long
Set wkb = ActiveWorkbook
Set wks = wkb.Worksheets("PB Life for BW")
x = wks.Range("A100").End(xlUp).Row
Set wd = CreateObject("Word.Application")
Set doc = wd.Documents.Add
wd.Visible = True
doc.Paragraphs(1).Range.InsertAfter vbCrLf
doc.Bookmarks.Add Name:="XL1", Range:=doc.Paragraphs(1).Range
doc.Bookmarks.Add Name:="XL2", Range:=doc.Paragraphs(2).Range
Set rng = wks.Range("A2:H30")
doc.Bookmarks("XL1").Select
Selection = rng
Set rng = wks.Range("A31:H" & x)
doc.Bookmarks("XL2").Select
Selection = rng
Set doc = Nothing
Set wd = Nothing
End Sub
Excel cells into a Word bookmark as a table. I used the code below.
The code ran all the way through - but absolutely nothing showed up in
Word!!
Help??!?
Ed
Sub XLtoWord()
Dim wd As Object 'Word.Application
Dim doc As Object 'Word.Document
Dim wkb As Workbook 'This workbook
Dim wks As Worksheet 'This workbook
Dim rng As Range 'This workbook
Dim x As Long
Set wkb = ActiveWorkbook
Set wks = wkb.Worksheets("PB Life for BW")
x = wks.Range("A100").End(xlUp).Row
Set wd = CreateObject("Word.Application")
Set doc = wd.Documents.Add
wd.Visible = True
doc.Paragraphs(1).Range.InsertAfter vbCrLf
doc.Bookmarks.Add Name:="XL1", Range:=doc.Paragraphs(1).Range
doc.Bookmarks.Add Name:="XL2", Range:=doc.Paragraphs(2).Range
Set rng = wks.Range("A2:H30")
doc.Bookmarks("XL1").Select
Selection = rng
Set rng = wks.Range("A31:H" & x)
doc.Bookmarks("XL2").Select
Selection = rng
Set doc = Nothing
Set wd = Nothing
End Sub