PC Review


Reply
Thread Tools Rate Thread

Copy Paste from Excel to specified word document

 
 
=?Utf-8?B?cmFwaGllbDIwNjM=?=
Guest
Posts: n/a
 
      10th Sep 2007
Ok. I've got the below code and it seems to work fine all the way up to where
it's going to paste into word (last sub) and it has an error. I want it to
paste the copied cells in to word (as unformatted text). It keeps throwing up
an error runtime error 1004. Any ideas?



Sub CopyCellsFromExcel()

Dim wordApp As Object
Dim fNameAndPath As String
Dim wdPastetext As String

ActiveSheet.Range("I5:I49").Copy
Application.CutCopyMode = False

Sub OpenAWordFile()


fNameAndPath = "C:\Documents and Settings\tom.jordan\My
Documents\Projects\FFEC Headed Paper.doc"
Set wordApp = CreateObject("Word.Application")
wordApp.Documents.Open (fNameAndPath)
wordApp.Visible = True

Selection.PasteSpecial DataType:=wdPastetext

End Sub
 
Reply With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      10th Sep 2007
You've got a couple of things going on here. One, you are using
variables in both subs but only have them declared in
CopyCellsFromExcel. While that may work if you don't have Option
Explicit stated, it is not good coding practice. Second, you have two
Sub start lines but only one End Sub. Third, you have
Application.CutCopyMode set to false right after you perform the cut.
That line will remove anything you have stored on teh clipboard, so
there would be nothing to place in Word. I combined the two subs, but
you could always break them apart if you need to.
Sub OpenAWordFile()
Dim wordApp As Object
Dim fNameAndPath As String
ActiveSheet.Range("A1:A9").Copy
fNameAndPath = "C:\Documents and Settings\tom.jordan\My" & _
"Documents\Projects\FFEC Headed Paper.doc"
Set wordApp = CreateObject("Word.Application")
With wordApp
.Documents.Open (fNameAndPath)
.Visible = True
.Selection.PasteAndFormat (wdPasteDefault)
End With
Set wordApp = Nothing
Application.CutCopyMode = False
End Sub
raphiel2063 wrote:
> Ok. I've got the below code and it seems to work fine all the way up to where
> it's going to paste into word (last sub) and it has an error. I want it to
> paste the copied cells in to word (as unformatted text). It keeps throwing up
> an error runtime error 1004. Any ideas?
>
>
>
> Sub CopyCellsFromExcel()
>
> Dim wordApp As Object
> Dim fNameAndPath As String
> Dim wdPastetext As String
>
> ActiveSheet.Range("I5:I49").Copy
> Application.CutCopyMode = False
>
> Sub OpenAWordFile()
>
>
> fNameAndPath = "C:\Documents and Settings\tom.jordan\My
> Documents\Projects\FFEC Headed Paper.doc"
> Set wordApp = CreateObject("Word.Application")
> wordApp.Documents.Open (fNameAndPath)
> wordApp.Visible = True
>
> Selection.PasteSpecial DataType:=wdPastetext
>
> End Sub


 
Reply With Quote
 
=?Utf-8?B?cmFwaGllbDIwNjM=?=
Guest
Posts: n/a
 
      12th Sep 2007
JW

Oops. I hadn't actually had two subs as I had merged them into one but
forgot to take out the second sub declaration out of this post. I've put in
your code into my excel sheet and it works. However, it pastes the table and
everything. I need this particular macro to paste the excel group into Word
as unformatted text i.e. it looks like normal text, no tables or anything.

Any idea how to do that?

"JW" wrote:

> You've got a couple of things going on here. One, you are using
> variables in both subs but only have them declared in
> CopyCellsFromExcel. While that may work if you don't have Option
> Explicit stated, it is not good coding practice. Second, you have two
> Sub start lines but only one End Sub. Third, you have
> Application.CutCopyMode set to false right after you perform the cut.
> That line will remove anything you have stored on teh clipboard, so
> there would be nothing to place in Word. I combined the two subs, but
> you could always break them apart if you need to.
> Sub OpenAWordFile()
> Dim wordApp As Object
> Dim fNameAndPath As String
> ActiveSheet.Range("A1:A9").Copy
> fNameAndPath = "C:\Documents and Settings\tom.jordan\My" & _
> "Documents\Projects\FFEC Headed Paper.doc"
> Set wordApp = CreateObject("Word.Application")
> With wordApp
> .Documents.Open (fNameAndPath)
> .Visible = True
> .Selection.PasteAndFormat (wdPasteDefault)
> End With
> Set wordApp = Nothing
> Application.CutCopyMode = False
> End Sub
> raphiel2063 wrote:
> > Ok. I've got the below code and it seems to work fine all the way up to where
> > it's going to paste into word (last sub) and it has an error. I want it to
> > paste the copied cells in to word (as unformatted text). It keeps throwing up
> > an error runtime error 1004. Any ideas?
> >
> >
> >
> > Sub CopyCellsFromExcel()
> >
> > Dim wordApp As Object
> > Dim fNameAndPath As String
> > Dim wdPastetext As String
> >
> > ActiveSheet.Range("I5:I49").Copy
> > Application.CutCopyMode = False
> >
> > Sub OpenAWordFile()
> >
> >
> > fNameAndPath = "C:\Documents and Settings\tom.jordan\My
> > Documents\Projects\FFEC Headed Paper.doc"
> > Set wordApp = CreateObject("Word.Application")
> > wordApp.Documents.Open (fNameAndPath)
> > wordApp.Visible = True
> >
> > Selection.PasteSpecial DataType:=wdPastetext
> >
> > End Sub

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open & copy paste a word document in excel using macros? Amit Raokhande Microsoft Excel Programming 1 31st May 2010 06:02 AM
How do I copy and paste the bit map to word document =?Utf-8?B?TEFUSEE=?= Microsoft Word Document Management 2 13th Aug 2006 11:38 PM
copy multiple worksheets of a workbook, and paste onto a Word document ( either create new doc file or paste onto an existing file.) I need this done by VBA, Excel Macro Steven Microsoft Excel Programming 1 17th Oct 2005 08:56 AM
how to copy all comments in one word document, paste into another. =?Utf-8?B?U2hhd24=?= Microsoft Word Document Management 1 22nd Mar 2005 08:28 PM
cut or copy and paste a word document Jim OBrien Microsoft Word Document Management 1 8th Aug 2003 11:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:36 AM.