Solved

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

Posted on 2014-11-15
2
480 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 81

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vlookup for in-between dates 4 37
Excel VBA 10 38
Excel conditional formatting based on 'zero value' 6 18
Excel Question 17 15
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 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