View Full Version : How to save screen as gif file
dmat619
10-21-2008, 12:19 PM
I am fairly new to VBA. I am trying to find a way to get a screen shot of a worksheet and save it as a .gif file. If it is a chart, I found that I can export it to a gif file. The problem is that the image I need to capture is a mixture of data and a chart stored on a worksheet. Can anyone help me please?
Thanks,
dmat619
jfournier
10-21-2008, 01:08 PM
You can use the CopyPicture method of a range to copy an image of a range to the clipboard.  If a chart is over the specified range it will be included in the image.  You'd then have to work on sending the clipboard contents to a gif file...
jfournier
10-21-2008, 01:14 PM
This is a good thread discussing what you want to do, I think:
http://forums.microsoft.com/msdn/showpost.aspx?postid=616253&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=0  (http://forums.microsoft.com/msdn/showpost.aspx?postid=616253&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=0)
jolivanes
10-21-2008, 01:44 PM
I went wrong somewhere on the last post.
My apologies.
 
' Author : Roy Cox (royUK)
' Website : www.excel-it.com (http://www.excel-it.com)] more examples
' Purpose : Copy a range as a picture
' Disclaimer; This code is offered as is with no guarantees. You may use it in your projects but please leave this header intact.
 
 
Option Explicit 
Sub paste_Picture() 
    Application. ScreenUpdating = True 
    Dim UserRange As Range 
    Dim OutputRange As Range 
    Dim MyPrompt As String 
    Dim MyTitle As String 
     'Prompt user for range to capture
    MyPrompt = "Select the range you would like to capture." 
    MyTitle = "User Input Required" 
    On  Error Resume Next 
    Set UserRange = Application.InputBox(Prompt:=MyPrompt, _ 
    Title:=MyTitle, Default:=ActiveCell.Address, Type:=8) 
    If UserRange Is Nothing Then End 
    On Error Goto 0 
     'Copy range to Clipboard as picture
    UserRange.CopyPicture 
     'Prompt user for range to paste to
    MyPrompt = "Select the range on which you would like to paste." 
    MyTitle = "User Input Required" 
    On Error Resume Next 
    Set OutputRange = Application.InputBox(Prompt:=MyPrompt, _ 
    Title:=MyTitle, Default:=ActiveCell.Address, Type:=8) 
    If OutputRange Is Nothing Then End 
    On Error Goto 0 
     'Paste picture to output range
    OutputRange.PasteSpecial 
    Selection.Formula = UserRange.Address 
End Sub 
Thanks to royUK
HTH
dmat619
10-22-2008, 07:50 AM
Thank you both for your help.  I found my solution by following the link provided by jfournier.
lucas
10-22-2008, 10:14 AM
bad post by jolivanes deleted.
jolivanes
10-22-2008, 03:02 PM
Thank you lucas
 
Regards
 
John
mdmackillop
10-22-2008, 03:21 PM
Hi Jolivanes.
You need to use vba tags (or the green vba button) for code in this forum. 
Regards
MD
jolivanes
10-22-2008, 06:06 PM
Hello mdmackillop.
 
Didn't I use the code tags on #4? If I didn't, my apologies.
The first one, the one lucas deleted was a copy/paste problem. Sorry about that.
 
Regards.
 
John
mdmackillop
10-23-2008, 12:39 AM
Hi John,
You used Code which doesn't work here.  No problem.
Regards
MD
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.