Passing image as variable.

jblevins

Active Member
Joined
Sep 2, 2013
Messages
250
Office Version
  1. 2003 or older
Trying to pass an image as a variable to API. Have tried "OleObjects", "Shapes" and "Controls".

VBA Code:
Sub AddFormIcon(TitlebarCaption, WBName, SHName, img)  ' Pass "img" from here to

Dim hwnd As Long
Dim lngRet As Long
Dim hIcon As Long
   
    hIcon = Workbooks(WBName).Worksheets(SHName).img.Picture.Handle  ' here
   
    hwnd = FindWindow(vbNullString, TitlebarCaption)   ' Form caption, not name; for form use frmName.Caption.
    lngRet = SendMessage(hwnd, WM_SETICON, ICON_SMALL, ByVal hIcon)
    lngRet = SendMessage(hwnd, WM_SETICON, ICON_BIG, ByVal hIcon)
   
    lngRet = DrawMenuBar(hwnd)
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Tried passing as "Shapes", maybe I don't understand what you mean by "Shape object"?
 
Upvote 0
Try...

VBA Code:
hIcon = img.Picture.Handle

Hope this helps!
 
Upvote 0
Tried passing "Image1" to
VBA Code:
hIcon = img.Picture.Handle
but it failed.

I have only got this to work by passing this
VBA Code:
ActiveWorkbook.Sheets("Sheet1").Image1.Picture.Handle
to
VBA Code:
hIcon = img
and it worked which means I am actually passing the handle.
 
Upvote 0
When calling AddFormIcon, you should be passing your image like this...

VBA Code:
Call AddFormIcon("MyTitlebarCaption", "MyWorkbookName", "MySheetName", ActiveWorkbook.Sheets("Sheet1").Image1)

Or, if you prefer, without the Call keyword...

VBA Code:
AddFormIcon "MyTitlebarCaption", "MyWorkbookName", "MySheetName", ActiveWorkbook.Sheets("Sheet1").Image1

Then you can retrive its handle like this...

VBA Code:
hIcon = img.Picture.Handle

Does this help?
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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