Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
On-the-fly determination of object type?
I like to use the CopyAsPicture function. Unfortunately (at least in
XL2000), I need to code in the correct object type. I have Dim rng As Range Set rng = Selection rng.CopyPicture xlPrinter, xlPicture but that won't work for graphics or charts. Then I tried removing "As Range" to make a general variable, but that still won't work on everything. Is there any way I can maybe do something like: Dim var Set var = Selection Obj$ = var.Type Dim obj As Obj$ Set obj = var obj.CopyPicture xlPrinter, xlPicture Ed |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
On-the-fly determination of object type?
Roedd <<Ed wedi ysgrifennu:
I like to use the CopyAsPicture function. Unfortunately (at least in XL2000), I need to code in the correct object type. I have Dim rng As Range Set rng = Selection rng.CopyPicture xlPrinter, xlPicture but that won't work for graphics or charts. Then I tried removing "As Range" to make a general variable, but that still won't work on everything. I think your problem is that when you select what looks like a chart, you are in fact selecting a chartarea object which doesn't have a CopyPicture method. Try this: Sub test() Dim var As Object Set var = Selection If TypeName(var.Parent) = "Chart" Then var.Parent.CopyPicture xlPrinter, xlPicture Else var.CopyPicture xlPrinter, xlPicture End If End Sub -- Rob http://www.asta51.dsl.pipex.com/webcam/ This message is copyright Robert Bruce and intended for distribution only via NNTP. Dissemination via third party Web forums with the exception of Google Groups and Microsoft Communities is strictly prohibited and may result in legal action. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
On-the-fly determination of object type?
Thank you, Rob. When I select the chart, the CopyAsPicture is available on
the Shift+Edit menu, so it looks to me like I've got a good object according to Excel. But VBA apparently wants the object spelled out, or it won't approve the Method. I could write a bunch of Ifs based on var.Type or TypeName or such; I was hoping to avoid that, though. All I want is a macro that will do anything I'm thinking of on any object I click - that's not too much to ask, is it?? 8P Ed "Robert Bruce" <rob@analytical-dynamicsdotcodotukay wrote in message ... Roedd <<Ed wedi ysgrifennu: I like to use the CopyAsPicture function. Unfortunately (at least in XL2000), I need to code in the correct object type. I have Dim rng As Range Set rng = Selection rng.CopyPicture xlPrinter, xlPicture but that won't work for graphics or charts. Then I tried removing "As Range" to make a general variable, but that still won't work on everything. I think your problem is that when you select what looks like a chart, you are in fact selecting a chartarea object which doesn't have a CopyPicture method. Try this: Sub test() Dim var As Object Set var = Selection If TypeName(var.Parent) = "Chart" Then var.Parent.CopyPicture xlPrinter, xlPicture Else var.CopyPicture xlPrinter, xlPicture End If End Sub -- Rob http://www.asta51.dsl.pipex.com/webcam/ This message is copyright Robert Bruce and intended for distribution only via NNTP. Dissemination via third party Web forums with the exception of Google Groups and Microsoft Communities is strictly prohibited and may result in legal action. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
coefficient of determination | Excel Worksheet Functions | |||
Average determination | Excel Worksheet Functions | |||
automation object type library reference | Excel Programming | |||
Combination Determination? | Excel Programming | |||
How to find what object type is returned from Selection property ? | Excel Programming |