View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Shawn O'Donnell Shawn O'Donnell is offline
external usenet poster
 
Posts: 42
Default Open JPG and determine pixel width in VB?

"Joe HM" wrote:
I added a Form and inserted an Image. Now I just don't
know how to hide that form and how to load the image?


I was thinking you could just add a form to the Excel VBAProject and put the
Image control on it. Then set the Image control's Picture property with
LoadPicture.

Sub ChangePicture(PicturePath as String)
UserForm1.Image1.Picture = LoadPicture(PicturePath)
End Sub

Just talking to UserForm1 like that should Load it, but not Show it. So
there should be no need to hide the form.

Then you can make a User-Defined Function like this that you can use in a
cell on the spreadsheet:

Public Function GetGraphicsWidth(filePath As String) As Double
ChangePicture (filePath)
GetGraphicsWidth = PixelsPerPoint * UserForm1.Image1.Width
End Function