Article ID: 149830
Article Last Modified on 1/19/2007
Sub PasteTableToWord()
Dim obj As Object
Dim temp As String
'Activate the worksheet containing the range to be copied
Worksheets("sheet1").Activate
'Select the range the of cells to be copied; update to match
'your data
Range("a1:c10").Select
'Copy the cells
Selection.Copy
'Create a word object.
Set obj = CreateObject("word.basic")
'Create a new file.
obj.filenew
'Determine if Microsoft Excel is running on the Macintosh or
'Windows.
'If Microsoft Excel is running on the Macintosh.
If (Application.OperatingSystem Like "*Mac*") Then
'Activate Word on the Macintosh
AppActivate "Microsoft word"
'Paste the Microsoft Excel Spreadsheet object into Word
obj.EditPasteSpecial IconNumber:=0, Link:=1, DisplayIcon:=0, _
Class:="Excel.Sheet.5", DataType:="Object", IconFilename:="", _
Caption:="Microsoft Excel 5.0 Worksheet"
'If Microsoft Excel is running on Windows NT/95/3.x
Else
'If you are using Word 7.0, use this line to make Word visible.
' If Word 6.0 is being used, by default Word starts visible.
If (obj.appinfo(2) Like "7.0") Then obj.AppShow
'Paste the Microsoft Excel Spreadsheet object into Word
obj.EditPasteSpecial Link:=1, Class:="Excel.Sheet.5", _
DataType:="Object", IconFilename:="", _
Caption:="Microsoft Excel Worksheet"
End If
'Save the file
obj.FileSaveAs Name:="testdoc.doc"
'Close Word.
Set obj = Nothing
'Return to Microsoft Excel. If this line is not used, the focus
'may be set to another Windows Application
AppActivate "Microsoft Excel"
'Deselect the selected range
Application.CutCopyMode = False
End Sub
120979 How to Use Named WordBasic Arguments in OLE Automation
120198 XL: How to Select Cells/Ranges Using Visual Basic Procedures
Additional query words: 8.00 XL
Keywords: kbdtacode kbhowto kbinterop kbprogramming kbualink97 KB149830