+ Reply to Thread
Results 1 to 19 of 19

Saving BMP Image Using VBA

  1. #1
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Saving BMP Image Using VBA

    Morning All,

    After completing a quick search for a similar piece of code I was able to locate the following from circa 2005:

    PHP Code: 
    Option Explicit

    Private Sub SaveRngAsBMP(Rng As RangeFileName As String)
    Rng.CopyPicture xlScreenxlBitmap
    SavePicture PastePicture
    (xlBitmap), FileName
    End Sub

    Sub TestIt
    ()
    Dim Rng As Range, Fn As String
    Set Rng 
    Range("A1:A5")
    Fn = 
    "C:\MyFile.bmp"
    SaveRngAsBMP Rng, Fn
    End Sub 
    The problem I'm having is, that code looks like it would never work to me, and I certainly can't seem to make it work.

    Effectively I intend to push a variable range into it by using "Set Rng=ImageRange", with ImageRange being a variable determined by another subroutine. The ImageRange will then be saved as a picture (it's for a widget style of reporting that only supports images unfortunately).

    Does anyone have any ideas? The second I mess around with the order the code is written in, or any of the variables, it fails, so I'm at a loss unfortunately.

    Cheers,

    Harry.

  2. #2
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Saving BMP Image Using VBA

    Is it missing a sub/function called PastePicture?

  3. #3
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Re: Saving BMP Image Using VBA

    Quote Originally Posted by kersplash View Post
    Is it missing a sub/function called PastePicture?
    So it would appear, but the code I copied didn't have it in and unfortunately the original website is down.

    Do you have any ideas?

  4. #4
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Saving BMP Image Using VBA

    I found a function on this page, not sure if it's related to what you are trying to do or not.

    http://www.vbaexpress.com/forum/show...ata-as-picture

  5. #5
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Re: Saving BMP Image Using VBA

    Quote Originally Posted by kersplash View Post
    I found a function on this page, not sure if it's related to what you are trying to do or not.

    http://www.vbaexpress.com/forum/show...ata-as-picture
    Not exactly, I want to save a BMP image of the selected range.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Saving BMP Image Using VBA

    The PastePicture function that is missing from your code is on the link that kersplash posted.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Saving BMP Image Using VBA

    How about this.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  8. #8
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Re: Saving BMP Image Using VBA

    Quote Originally Posted by bakerman2 View Post
    How about this.
    Please Login or Register  to view this content.
    Bakerman, I tried to test this but have a couple of questions.

    Firstly, it looks like I need to add some code for defining "rng" is that correct?
    Finally, when i paste your code in, I can't run or step through it, any ideas?

    Thanks for your time, appreciate it.

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Saving BMP Image Using VBA

    All is defined in TestIt so it's that code you need to run.

  10. #10
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Re: Saving BMP Image Using VBA

    Quote Originally Posted by bakerman2 View Post
    All is defined in TestIt so it's that code you need to run.
    Didn't even notice that part at first haha.

    I'm getting a 1004 error when i get to ".Chart.Paste" - could this be because the data it's copying is part of a pivot table?

    Thanks again.

  11. #11
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Re: Saving BMP Image Using VBA

    Any ideas anyone?

  12. #12
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Saving BMP Image Using VBA

    Please Login or Register  to view this content.
    Last edited by humdingaling; 06-19-2018 at 04:01 AM. Reason: just made it like your example
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  13. #13
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Re: Saving BMP Image Using VBA

    Quote Originally Posted by humdingaling View Post
    Please Login or Register  to view this content.
    That seem's to be working very well, thank's for that.

    Another question I have is, if i wanted to make the file name and range a variable, what would be the syntax?

    I've tried ActiveSheet.Range(PictureRange), for the range, but i'm receiving a 1004 error.

  14. #14
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Saving BMP Image Using VBA

    The named range must be inside double quotes.
    Please Login or Register  to view this content.
    Last edited by bakerman2; 06-19-2018 at 07:58 AM.

  15. #15
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Re: Saving BMP Image Using VBA

    Quote Originally Posted by bakerman2 View Post
    The named range must be inside double quotes.
    Please Login or Register  to view this content.
    Thanks for the reply.

    I'm using the following code to set "PictureRange".

    PHP Code: 
    Set PictureRange ActiveSheet.Range(Cells(11), Cells(LastRow16)) 
    Then I'm trying to reference it by using:

    PHP Code: 
    Set Plage ActiveSheet.Range(PictureRange
    I can't see where the double quotes would go, i'm effectively passing the range between 2 variables, so I don't understand what the error is actually telling me. I can select the range and that seems to work fine.

    Thanks again for all your help.

  16. #16
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Saving BMP Image Using VBA

    I think it would just be
    Please Login or Register  to view this content.
    or simply use PictureRange instead of plage in the rest of the code.

  17. #17
    Forum Contributor
    Join Date
    12-02-2014
    Location
    England
    MS-Off Ver
    2010 | 2016
    Posts
    167

    Re: Saving BMP Image Using VBA

    Quote Originally Posted by xlnitwit View Post
    I think it would just be
    Please Login or Register  to view this content.
    or simply use PictureRange instead of plage in the rest of the code.
    That seems to have worked, sometimes it's the simple fixes!

  18. #18
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: Saving BMP Image Using VBA

    The following macro code works perfectly for me Harry. This is a combination of what I already had and then help from this forum:

    Please Login or Register  to view this content.
    I have put red text on the only thing you'll need to amend (the range for your export).

    It also allows you to save the file wherever you wish and also choose the file name of your choice.

    Hope this helps

  19. #19
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Saving BMP Image Using VBA

    aah yes sorry

    i originally got the code from french site
    thats the reason i use "PLAGE"
    ie plage de cellules = cell range

    kind of stuck using it
    anyways seems like its been fixed

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Batch Image saving
    By mattquintadena in forum Excel General
    Replies: 19
    Last Post: 03-18-2022, 05:22 AM
  2. EXCEL, VBA, Image: Image loses transparency after saving woorkbook
    By lhasha in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-19-2016, 11:13 PM
  3. VBA Script for saving an image from Excel to PNG file thru MS Paint
    By alexgempesaw in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-21-2015, 08:09 PM
  4. Excel 2010 "vlookup pictures vba" links image instead of saving it as an image
    By neverdom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-28-2013, 04:17 AM
  5. saving an image of my screen
    By jt1561 in forum Excel General
    Replies: 2
    Last Post: 03-12-2009, 01:33 PM
  6. Saving a chart as an image
    By treetopdewdrop in forum Excel General
    Replies: 3
    Last Post: 07-24-2008, 12:47 PM
  7. saving image
    By Scott McDermott in forum Excel General
    Replies: 22
    Last Post: 04-01-2007, 02:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1