PC Review


Reply
Thread Tools Rate Thread

Copy paste different columns (ranges) to word

 
 
pedro
Guest
Posts: n/a
 
      3rd Jan 2008
Hi I have problems when I try to copy paste different columns (ranges)
to a word doc.


This is the code I'm using:

Dim wordapp As Word.Application
Dim WordDoc As Word.Document

Set wordapp = New Word.Application
Set WordDoc = wordapp.Documents.Add

WordDoc.PageSetup.Orientation = wdOrientLandscape

Dim x As Integer
x = max + 1
Sheets("registrations").Range("B1:F" & x & ",I1:I" & x & ",K1:L" &
x & ",N1:N" & x).Copy
WordDoc.Range.PasteSpecial


The problem that I have, is that it doesn't copy the different
columns, it copies all the columns between B and N, so G, H, J, M are
alsow included.

Now I noticed that the same thing occurs when I try to simulate this
with manual actions. If I select 2 columns for example A and C, copy
and past them in a Word doc, column B is also been copied.

What I alsow tried was to delete the unneeded columns afterwards: with
this code:

WordDoc.Tables(1).Columns(12).Delete
WordDoc.Tables(1).Columns(10).Delete
WordDoc.Tables(1).Columns(8).Delete
WordDoc.Tables(1).Columns(7).Delete

But then I receive the following error:

"Cannot access individual columns in this collection because the table
has mixed cell widths."

I alsow tried copy pasting the ranges one after another, ben the I
receive the following error:

"Microsoft excel is waiting for an OLE object to ..."

Somebody knows a solutions for this situation.

Thanks in advance, Nik
 
Reply With Quote
 
 
 
 
Smallweed
Guest
Posts: n/a
 
      3rd Jan 2008
It's always a problem: you cannot paste multiple ranges from Excel to any
package other than Excel - the clipboard thinks you've copied everything
between. You best bet (I think) is to create the table you would like to see
in Word in Excel first - either with a macro or - better - worksheet formulae
and then copy that in its entirety.

"pedro" wrote:

> Hi I have problems when I try to copy paste different columns (ranges)
> to a word doc.
>
>
> This is the code I'm using:
>
> Dim wordapp As Word.Application
> Dim WordDoc As Word.Document
>
> Set wordapp = New Word.Application
> Set WordDoc = wordapp.Documents.Add
>
> WordDoc.PageSetup.Orientation = wdOrientLandscape
>
> Dim x As Integer
> x = max + 1
> Sheets("registrations").Range("B1:F" & x & ",I1:I" & x & ",K1:L" &
> x & ",N1:N" & x).Copy
> WordDoc.Range.PasteSpecial
>
>
> The problem that I have, is that it doesn't copy the different
> columns, it copies all the columns between B and N, so G, H, J, M are
> alsow included.
>
> Now I noticed that the same thing occurs when I try to simulate this
> with manual actions. If I select 2 columns for example A and C, copy
> and past them in a Word doc, column B is also been copied.
>
> What I alsow tried was to delete the unneeded columns afterwards: with
> this code:
>
> WordDoc.Tables(1).Columns(12).Delete
> WordDoc.Tables(1).Columns(10).Delete
> WordDoc.Tables(1).Columns(8).Delete
> WordDoc.Tables(1).Columns(7).Delete
>
> But then I receive the following error:
>
> "Cannot access individual columns in this collection because the table
> has mixed cell widths."
>
> I alsow tried copy pasting the ranges one after another, ben the I
> receive the following error:
>
> "Microsoft excel is waiting for an OLE object to ..."
>
> Somebody knows a solutions for this situation.
>
> Thanks in advance, Nik
>

 
Reply With Quote
 
pedro
Guest
Posts: n/a
 
      3rd Jan 2008
mmm, thought of that to, but was asking my self if there wasn't
another solution avoiding to make extra sheets, but thanks anyway,
have solved it like that.

Grtz, Nik
 
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 can I copy big ranges of cells without drag or copy/paste? Ricardo Julio Microsoft Excel Misc 3 23rd Mar 2010 02:38 PM
Copy/Paste dynamic ranges kevin Microsoft Excel Programming 1 28th May 2009 07:14 PM
copy paste different ranges Khalil Handal Microsoft Excel Discussion 3 16th Aug 2007 06:07 PM
Copy and paste Named Ranges Robert H Microsoft Excel Programming 6 6th Feb 2007 04:13 PM
Copy and paste two named ranges together. =?Utf-8?B?QUNEZW52ZXI=?= Microsoft Excel Discussion 3 20th Oct 2005 11:36 PM


Features
 

Advertising
 

Newsgroups
 


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