View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Robert Bruce[_2_] Robert Bruce[_2_] is offline
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.