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
Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
stuck in average-1 12 65
Batch Numbering 6 30
How can I calculate a balloon payment in Excel? 5 14
Copy column before Column A using a macro 6 14
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

856 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