View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 293
Default Copy to a Word Table

Hi joel,


word usually requires selection

Not so - not by a longshot!! Using selections is almost always avoidable and the preferred method is to work with ranges. All you
need to do is to specify them correctly, just as you do in Excel.


--
Cheers
macropod
[Microsoft MVP - Word]


"joel" wrote in message ...

Excel is much easy to work with than Word. In excel you don't need to
select the areas. becauwse you are owrking with two documents and word
usually requires selection I recommend defining the excel area before
opening up the word document. try this code


Sub WordTable()

Dim i As Integer
Dim appWd As Word.Application
Dim mydoc As document

FName = "c:\temp\joel.doc"

With ActiveWorkbook.Sheets("Sheet2")
noRows = .Range("A" & Rows.Count).End(xlUp).Row
noCols = .Cells(1, Columns.Count).End(xlToLeft).Column
Set CopyRange = .Range(.Range("A1"), .Cells(noRows, noCols))
End With

Set appWd = GetObject(FName)
appWd.visible = true
Set Mydocument = appWd.document

Selection.GoTo What:=wdGoToBookmark, Name:="CommTable"
Selection.InsertRowsAbove noRows
Selection.MoveDown Unit:=wdLine, Count:=noRows, Extend:=wdExtend
CopyRange.Copy
Selection.Paste


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=171622

Microsoft Office Help