LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VB automated pasting of Excel range into Word document

I'm trying to write VB code to paste several Excel ranges into a Word
document, as required by my employer.

I'm able to do this satisfactorily using manual cut and paste (Office 2003),
but when I automate it, I get "Run-time error 438: object doesn't support
this method". I get this error whether I use Selection. or a variable Dim as
Excel.Range or Word.Range or Object. I also get the error regardless of the
type of paste I use. Pasted images aren't acceptable because the range may
span several pages.

Below is a code example. The errant command is flagged between '*****
comments. Otherwise, the code runs as designed. The GetWordApp is from a
previous post that I found useful (thanks!)

I would appreciate any help you can give.

Thanks,

Dave in Madison

Sub PrintToWordFile()

Const fname = "C:\Test.doc"
Const rname = "EntireBudget"

Dim a As Excel.Range ' print range
Dim g As Boolean ' gridlines flag
Dim o As Object ' word application
Dim w As Word.Document ' document within word application

g = ActiveWindow.DisplayGridlines
ActiveWindow.DisplayGridlines = False
Set a = Range(rname)
a.Copy

GetWordApp o
With o
.Visible = True
.Documents.Open Filename:=fname, ReadOnly:=False
Set w = .Documents(fname)
End With

'*****

a.PasteExcelTable _
LinkedToExcel:=False, _
WordFormatting:=False, _
RTF:=True

'*****

w.SaveAs "C:\Test.doc"
o.Application.Quit

ActiveWindow.DisplayGridlines = g
Set w = Nothing
Set o = Nothing
End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2007 - link named excel range to word document Karin Excel Discussion (Misc queries) 0 February 8th 10 09:36 PM
Inserting data into Word document by a range of dates from Excel spreadsheet Gordon[_6_] New Users to Excel 3 July 29th 08 08:22 PM
Pasting Excel ('07) Range with Chart in Word ('07) Blaknecr8 Charts and Charting in Excel 0 January 11th 08 08:20 PM
Getting a range from Excel into a Word document daniB[_6_] Excel Programming 0 February 12th 04 02:40 PM
Pasting a Range to Word Ian Mangelsdorf Excel Programming 0 January 22nd 04 12:34 AM


All times are GMT +1. The time now is 10:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"