Solved

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

Posted on 2014-11-15
2
441 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
2 Comments
 
LVL 80

Accepted Solution

by:
byundt earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now