Re: paste to word document and save

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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" <eyecalibrate.20x41b_1136055002.9873@xxxxxxxxxxxxxxxxxxxxx>
wrote in message
news:eyecalibrate.20x41b_1136055002.9873@xxxxxxxxxxxxxxxxxxxxxxxx
>
> I want to copy a section of an excel *** 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?action=getinfo&userid=6621
> View this thread: http://www.excelforum.com/showthread.php?threadid=497181
>


.


Quantcast