?
Solved

Excel userForm: cant resize .jpg graphic, and .png graphic 'invalid'

Posted on 2014-11-15
2
Medium Priority
?
568 Views
Last Modified: 2014-11-15
Hi,
This is my first experience of importing pics into Image ctls.
Both of the two pics studied here insert into an xl worksheet cell via .Shapes.AddPicture, without a problem. The xl cell height was for a font of Calibri, font 11 (so the final imported image size was quite small).

The only code within the attached xl file is shown below.
The attached .png and .jpg graphics files should be in same folder as xl file.
Run the UserForm from the activeX cmd on 'sheet 1'.

Please can you show me how to get the jpg image to fit into the image ctl set before initialization to 42x48 and which expands to [114 x 132 (HxW)] when .Autosize is False?

I found no helpful additional Image.properties to help me forward.

When pathPic = "openVisio.png   the bug report is: 'graphic is invalid'.
What graphic types are permitted?

Thanks in anticipation,
Kelvin

Private Sub UserForm_Initialize()
    Dim pathPic As String
   
    pathPic = "Question Relationships.jpg"
    'pathPic = "openVisio.png" '''>>>>> "invalid picture" why, what file types are valid?
    'pathPic = "hello.jpg" '>>>> "file not found" - correct it was deliberately not there
   
    Debug.Print "pathPic = "; pathPic
    Image1.Picture = LoadPicture(pathPic)
    Image1.AutoSize = False 'True makes the control expand, not the graphic shrink
    Image1.Height = 42
    Image1.Width = 48
   
End Sub
Image-stuff.xlsm
openvisio.png
Question-Relationships.jpg
0
Comment
Question by:Kelvin4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 2000 total points
ID: 40445079
Kelvin,
There are only six file types supported with image control pictures (*.bmp, *.cur, *.gif, *.ico, *.jpg,  *.wmf), and the *.png is not one of them. For details, see MSDN Help on Image Control in Office 2013 http://msdn.microsoft.com/en-us/library/office/gg264279%28v=office.15%29.aspx 

To get the picture to autofit the image control, you want to set the .PictureSizeMode property to 1 (fmPictureSizeModeStretch)

Note the change (added a hyphen) I made to the file name "Question-Relationships.jpg"
Private Sub UserForm_Initialize()
    Dim pathPic As String
   
    pathPic = ThisWorkbook.Path & Application.PathSeparator & "Question-Relationships.jpg"
    'pathPic = ThisWorkbook.Path & Application.PathSeparator & "openVisio.png" '''>>>>> "invalid picture" why, what file types are valid?
    'pathPic = "hello.jpg" '>>>> "file not found" - correct it was deliberately not there
    
    'Debug.Print "pathPic = "; pathPic
    With Image1
        .Picture = LoadPicture(pathPic)
        .AutoSize = False 'True makes the control expand, not the graphic shrink
        .Height = 42    'Size of image control
        .Width = 48
        .PictureSizeMode = fmPictureSizeModeStretch     'Autosize picture to fit control
    End With
End Sub

Open in new window

Cheers!

Brad
0
 

Author Closing Comment

by:Kelvin4
ID: 40445244
Many thanks!
Kelvin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question