Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 the scrolling table in Microsoft Excel using the INDEX function.

717 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