Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default 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   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
coefficient of determination Jene Excel Worksheet Functions 2 August 27th 09 02:39 AM
Average determination Debra Excel Worksheet Functions 4 November 1st 04 01:22 PM
automation object type library reference Kevan Hanson Excel Programming 2 August 4th 04 02:29 AM
Combination Determination? Jeffrey Marcellus Excel Programming 1 June 3rd 04 03:41 AM
How to find what object type is returned from Selection property ? Krzysztof Klimczak[_3_] Excel Programming 1 October 2nd 03 11:33 PM


All times are GMT +1. The time now is 12:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"