Range CopyPicture()

G

GS80

Hi,

I'm working on an app which i need to copy a range of cells which is
programatically generated using the Excel object model. I want to be able to
select the output range which consists of charts and cells making up a table.
I'm using the CopyPicture() method of Range which i had woring once to copy
the charts and cells combination into word. Having run this again it won't
pull across the charts now. The areas where these are meant to go are just
blank.

Has anyone experienced this before and could maybe give me some information
on how to resolve this. I know it can be done as it worked once. I'm
wondering if the slight adjustment made to the chart upon which the output
charts are based has upset something. Copying manually seems to work but the
formatting is skewed somewhat, hence the requirement of the picture to be
used.

Any help will be greatly appreciated.

G
 
G

GS80

I did, and fair point about including the code.

I do however think that i have just resolved my problem. It appears that i
have to call the activate() method on the Worksheet containing the items I
need to copy. Without this method all i get is the cells and the cell data
returned.

Code will be forthcoming with any other posts.

Thanks,

G
 
G

GS80

Ok. Working with another data range now with the same idea, in this case its
only the last graph of 4 that doesn't appear. Strangely, if i ope the file
and modify a cell in the range to be copied, when running the app again to
copy the range, the top 2 graphs disappear. The code i use to copy is below:

ws = (Worksheet)wb.Worksheets["wsPres"];
ws.Activate();
testRange = ws.get_Range("A1:H44", missing);
testRange.CopyPicture(XlPictureAppearance.xlScreen,
XlCopyPictureFormat.xlPicture);
myDoc.Select();
wordApp.Selection.Paste();

The Excel and Word documents are opened prior to this code.
Hopefully the above code is enough to highlight what i maybe doing wrong. If
anything else is required let me know.

Thanks,

G
 
G

GS80

In addition to my last post. It seems to be down to what is visible on the
page when the document is saved. If I open the Excel document and scroll down
so only the 2 lowest graphs are visible, this appears to be all that is
displayed on the output. ERegardless of position, all cell data is copied as
expected. Not sure if this is of any more help.

G
 
J

Jon Peltier

If you reference your objects appropriately, you don't need to activate or
select anything. This test code gave me a picture of the appropriate region
in metafile format, even if another range was selected or another sheet was
active:

worksheets("Project Input (4)").range("F242:L262").copypicture
Appearance:=xlScreen, Format:=xlPicture

- Jon
 
G

GS80

Think i'll go back and check out my code. I got a solution by selecting the
usedrange() method of the current worksheet. I'll let you know how it goes by
looking at the way i reference my objects.

Thanks for your patience.

G
 
J

Jon Peltier

My code works fine even if the range to copy is scrolled off screen. I'm
using VBA, though, and I notice you're using that wacky dot net stuff. I
don't know whether there's any issue related to that.

- Jon
 
G

GS80

I'm thinking there may well be. There is a lot more casting of objects
required within C# than any VBA code i've seen, I've also noticed that there
are a number of methods that differ from the VBA equivalent. Unfortunately my
App has to be in C#. As i said, if i select the Usedrange() on the page i'm
interested in, i can select all appropriate data as a picture. This resolves
my issue just now but it does raise some concerns over the potential for
running into other issues like this.

Thanks for your help.

G
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top