![]() |
paste to word document and save
I want to copy a section of an excel sheet to a word document and save the word document. I have tried several senarios to no avail. My attempts do not recognize that the word document exists. What code do I use and do I need to do something special so that the excel workbook cooperates with word? Thank you, David -- eyecalibrate ------------------------------------------------------------------------ eyecalibrate's Profile: http://www.excelforum.com/member.php...fo&userid=6621 View this thread: http://www.excelforum.com/showthread...hreadid=497181 |
paste to word document and save
Something like this:
Sub PrintToWordFile() Const fname = "C:\Test.doc" Const rname = "A1:B10" Dim a As Excel.Range Dim g As Boolean Dim o As Object Dim w As Word.Document Dim wdRng as Word.Range g = ActiveWindow.DisplayGridlines ActiveWindow.DisplayGridlines = False Set a = Range(rname) a.Copy set o = CreateObject("Word.Application") ' or if word is open ' GetObject(, "Word.Application") With o .Visible = True .Documents.Open Filename:=fname, ReadOnly:=False Set w = .Documents(fname) set wdRng = selection End With '***** ' PASTE TABLE WdRng.PasteSpecial Link:=False, _ DataType:=1, Placement:=0, _ DisplayAsIcon:=False '' 1 = wdPasteRTF, 0 = wdInLine '***** w.SaveAs "C:\Test.doc" o.Application.Quit ActiveWindow.DisplayGridlines = g Set w = Nothing Set o = Nothing End Sub -- Regards, Tom Ogilvy "eyecalibrate" wrote in message news:eyecalibrate.20x41b_1136055002.9873@excelforu m-nospam.com... I want to copy a section of an excel sheet to a word document and save the word document. I have tried several senarios to no avail. My attempts do not recognize that the word document exists. What code do I use and do I need to do something special so that the excel workbook cooperates with word? Thank you, David -- eyecalibrate ------------------------------------------------------------------------ eyecalibrate's Profile: http://www.excelforum.com/member.php...fo&userid=6621 View this thread: http://www.excelforum.com/showthread...hreadid=497181 |
All times are GMT +1. The time now is 05:57 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com