Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy data from Excel to Word

Status
Not open for further replies.

neepshed

IS-IT--Management
Aug 17, 2002
27
0
0
GB
Hello, I am trying to create a macro that will copy a selection from Excel and paste special into Word (unformatted text).
Any thoughts on what I have so far. It fails when I do the paste special.

Thanks in advance.

Sub CreateText()
'
'

'
' COPY Data from Excel
Cells.Select
Selection.Copy

' Create Word Document
Set doc = CreateObject("Word.Application")
doc.Visible = True
doc.Documents.Add

'PASTE DATA
' doc.Documents.Add.Content.Paste
' appWrd.Selection.PasteSpecial DataType:=wdPasteText
' Rng.Select
appWrd.Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
wdInLine, DisplayAsIcon:=False

End Sub
 
What does "fail" mean exactly? It does not paste anything at all? It pastes in a way you don't want?

Curious. In your code the Word instance is "doc", as in:
Code:
Set [b]doc[/b] = CreateObject("Word.Application")
yet your paste line is
Code:
[b]appWrd[/b].Selection.PasteSpecial

Gerry
My paintings and sculpture
 
I get a run time error 424. Object required.

Yep. I'm not very good at this. So if you've got a solution I'd be very grateful.

 
You may try this:
Sub CreateText()
' COPY Data from Excel
ActiveSheet.Cells.Copy
' Create Word Document
Set doc = CreateObject("Word.Application")
doc.Visible = True
doc.Documents.Add
'PASTE DATA
doc.Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
wdInLine, DisplayAsIcon:=False
Set doc = Nothing
End Sub


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
And if you haven't referenced the word library:
Sub CreateText()
' COPY Data from Excel
ActiveSheet.Cells.Copy
' Create Word Document
Set doc = CreateObject("Word.Application")
doc.Visible = True
doc.Documents.Add
'PASTE DATA
doc.Selection.PasteSpecial Link:=False, DataType:=2, Placement:= _
0, DisplayAsIcon:=False
Set doc = Nothing
End Sub


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top