simple export a selection as an image?

RealJetJackson

New Member
Joined
Aug 11, 2008
Messages
22
All,

following the 'success' last week of my posts to get my charts exported as an image, I have moved on a bit and now want to export a selection from one of my sheets as an image too.

I have worked out that I can select part of a sheet to export like this :

Worksheets("Sheet1").Range("C6:D9").CopyPicture _
Appearance:=xlScreen, Format:=xlPicture

but how do I then 'write' it to a file, say a gif for instance?

something like blah.Export "C:\temp\test.gif", "GIF"?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi, try:

Code:
Dim vFile As Variant, sFilter As String, lPicType As Long, oPic As IPictureDisp

sFilter = "Windows Bitmap (*.bmp),*.bmp"

vFile = Application.GetSaveAsFilename(InitialFileName:="T:\Common\DIRMKT\Planning Team\Selections Monitor\Images", filefilter:=sFilter)

If vFile <> False Then
    lPicType = xlBitmap
    Set oPic = Worksheets("Sheet1").Range("C6:D9").CopyPicture _
Appearance:=xlScreen, Format:=xlPicture    SavePicture oPic, vFile
ActiveCell = vFile
End If
 
Upvote 0
ok, I have copy/pasted as you have written, but the Set oPic line turns read and throws and 'expected end of statement' error?
 
Upvote 0
CopyPicture does not return an object so that code won't work. Have a look at the code here for one method.
 
Upvote 0
:) yes, I've found that code already. It works.

I've been trying to wade through it, to extract just the bits I need and put them in a button rather than a separate macro, but I'm quite new to VB and I'm a bit lost!
 
Upvote 0
You need all of the code. Just call the GIF_Snapshot routine from the button and you should be fine.
 
Upvote 0
If it's a button from the Forms toolbar, just assign the GIF_Snapshot macro to it. If it's a button from the Control Toolbox, then you call it from the Click event:
Code:
Private Sub CommandButton1_Click()
   GIF_Snapshot
End Sub
 
Upvote 0
ok, I have used the XL2GIF code and hacked it around a bit to fix the selected range and to fix the name the file is exported as (the sheet name). Not pretty, but I understand most of it I think!

Cheers Guys.
 
Upvote 0

Forum statistics

Threads
1,214,579
Messages
6,120,365
Members
448,956
Latest member
Adamsxl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top