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
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.
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.
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).
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.
'***************************************************************************
'*
'* 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
'***************************************************************************
Last edited by VBAhack; May 29th, 2007 at 01:11 AM.