Results 1 to 16 of 16

Thread: Exporting an Excel Range as BMP or GIF

  1. #1

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Exporting an Excel Range as BMP or GIF

    Hi All

    I know how to export charts but now I want to export say Range("A1:L50") from say Sheet1 to a bitmap file so that I can display that in a picture box on the userform. The picture has to retain the formating of the Range.

    I have searched on the net but couldn't find any code/hints.

    Any help will be appreciated.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  2. #2
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Exporting an Excel Range as BMP or GIF

    Don't know if this helps, but you can copy a picture of a range to the clipboard:

    Code:
    Range("B4:E5").CopyPicture Appearance:=xlScreen, Format:=xlBitmap
    
    or
    
    Range("B4:E5").CopyPicture Appearance:=xlScreen, Format:=xlPicture
    You can do the same thing manually by selecting a range and clicking the edit menu while holding down the shift key.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Exporting an Excel Range as BMP or GIF

    You could use some API code to get the image off the clipborad and write it out to an image file.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Exporting an Excel Range as BMP or GIF

    Hi All

    Thanks for your replies...

    @VBAhack: I am already know how to export the image to the clipboard, but how do i save it to a BMP or GIFF file?

    @Rob: You know of any API that can help me?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Exporting an Excel Range as BMP or GIF

    OpenClipboard, GetClipboardData, and CloseClipboard.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Exporting an Excel Range as BMP or GIF

    OpenClipboard, GetClipboardData, and CloseClipboard.
    Err, Rob Like I said I know how to copy data to the clipboard. I want to save
    that data to a BMP or a Giff File....
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Exporting an Excel Range as BMP or GIF

    Once you have the data from the clipboard you would need to BitBlt API it to a DC where you could create a bitmap in memory and then save to a file. Its not really my area of knowledge but in the gaming forum they probably have threads on it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617
    Last edited by VBAhack; Mar 23rd, 2007 at 01:35 PM.

  9. #9

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Exporting an Excel Range as BMP or GIF

    @Rob: Thx for the tip. Will check that out...
    @VBAhack: I don't want to install a different utility. I want to do this from Excel using VBA code

    I think I have been misunderstood ... I'll explain once again....

    Using VBA Excel, I want to export say Range("A1:L50") from say Sheet1 to a bitmap file and save it as say myfile.bmp.

    Hope this helps....
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  10. #10
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Exporting an Excel Range as BMP or GIF

    You weren't misunderstood. The thought was that perhaps buried in the pages associated with those links was an API or reference to an API that you could use. I didn't have the time to crawl through them in detail - figured you could do that.

  11. #11

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Exporting an Excel Range as BMP or GIF

    I have already checked them... nothing
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  12. #12
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Exporting an Excel Range as BMP or GIF

    You might try a post in the API forum. What you are really trying to do is get an image from the clipboard to a file.......

  13. #13
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Exporting an Excel Range as BMP or GIF

    This might be promising:

    http://vb.mvps.org/articles/ap200106.asp

    Soup Up Office VBA by Karl E. Peterson

    Q. Paste a Clipboard Object to VBA
    .........
    .........
    Adding support for various graphical formats gets far more API-intensive. The main problem to overcome: making an in-memory copy of the data. I provided the CMemoryDC class for working with bitmaps in memory in my April column (see Resources); you can also find the class in this month's sample code, which you can download. I built into CMemoryDC the ability to "disconnect" a bitmap from its containing Picture object, as well as the ability to create a Picture object containing a copy of any bitmap given only the handle to the original.

    Add bitmap support to your new custom CClipboard object by adding CMemoryDC to your VBA project. Then write your CClipboard class's GetData and SetData methods, which duplicate the corresponding text methods almost exactly, except they leverage the CMemoryDC class's unique capabilities to disconnect bitmaps from their containers (see Listing A).

  14. #14
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Exporting an Excel Range as BMP or GIF


  15. #15

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Exporting an Excel Range as BMP or GIF

    Hi VBAHack

    Thanks for the link, I'll check it and post back the comments.

    Also ----- I admire your patience
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  16. #16
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Exporting an Excel Range as BMP or GIF

    Quote Originally Posted by koolsid
    Hi All

    I know how to export charts but now I want to export say Range("A1:L50") from say Sheet1 to a bitmap file so that I can display that in a picture box on the userform. The picture has to retain the formating of the Range.

    I have searched on the net but couldn't find any code/hints.

    Any help will be appreciated.
    Hey koolsid,

    I just stumbled on this. With a minor mod I was able to create a bmp of a range. See attached image below.

    http://www.bmsltd.ie/DLCount/DLCount...stePicture.zip

    Code:
    '***************************************************************************
    '*
    '* MODULE NAME:     Paste Picture
    '* AUTHOR & DATE:   STEPHEN BULLEN, Office Automation Ltd
    '*                  15 November 1998
    '*
    '* CONTACT:         [email protected]
    '* WEB SITE:        http://www.oaltd.co.uk
    '*
    '* DESCRIPTION:     Creates a standard Picture object from whatever is on the clipboard.
    '*                  This object can then be assigned to (for example) and Image control
    '*                  on a userform.  The PastePicture function takes an optional argument of
    '*                  the picture type - xlBitmap or xlPicture.
    '*
    '*                  The code requires a reference to the "OLE Automation" type library
    '*
    '*                  The code in this module has been derived from a number of sources
    '*                  discovered on MSDN.
    '*
    '*                  To use it, just copy this module into your project, then you can use:
    '*                      Set Image1.Picture = PastePicture(xlPicture)
    '*                  to paste a picture of whatever is on the clipboard into a standard image control.
    '*
    '* PROCEDURES:
    '*   PastePicture   The entry point for the routine
    '*   CreatePicture  Private function to convert a bitmap or metafile handle to an OLE reference
    '*   fnOLEError     Get the error text for an OLE error code
    '***************************************************************************
    Attached Images Attached Images  
    Last edited by VBAhack; May 29th, 2007 at 01:11 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width