How to open a picture just when it exists?

marlonsaveri

Board Regular
Joined
Jan 28, 2011
Messages
68
Hi,
When I use "On Error Resume Next", I avoid an error here:

Code:
mypicture = ThisWorkbook.Path & Application.PathSeparator & ActiveSheet.Name & "-" & mtx_prop(i, 1) & ".jpg"
    On Error Resume Next
    Image1.Picture = LoadPicture(mypicture)

However, i need something like this:
Code:
If picture exists: 
     Image1.Picture = LoadPicture(imagem)
Else
    Image1.visible = false
How could I write it?


And a second question:
Actually, a property (given by mtx_prop(i,1) could have more the one picture, so, I want something like this:

Code:
if, to this property, there was j pictures:
mypicture(1) = ThisWorkbook.Path & Application.PathSeparator & ActiveSheet.Name & "-" & mtx_prop(i, 1) & [B]j[/B] &  ".jpg"
     Image1.Picture = LoadPicture(mypicture(1))
mypicture(2) = ThisWorkbook.Path & Application.PathSeparator &  ActiveSheet.Name & "-" & mtx_prop(i, 1) & j &  ".jpg"
      [B]Image2[/B].Picture = LoadPicture(mypicture([B]2[/B]))
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
For your first question, try...

Code:
[font=Verdana][color=darkblue]If[/color] Dir(mypicture) <> "" [color=darkblue]Then[/color]
     Image1.Picture = LoadPicture(imagem)
[color=darkblue]Else[/color]
    Image1.Visible = [color=darkblue]False[/color]
[color=darkblue]End[/color] [color=darkblue]If[/color]
    [/font]
 
Upvote 0
Hi, thanks.
In this new way, I think we don't need chek if the image exists. However, I can't open the picture:
Code:
myfolder = ThisWorkbook.Path & Application.PathSeparator
firstname = ActiveSheet.Name & "_" 
Files = Dir(myfolder & firstname & "*.jpg*", vbArchive)    

j = 1
While Files <> vbNullString   
Set createpag = Me.MultiPage1.Pages.Add("page" & j, j, Me.MultiPage1.Pages.Count)    
Set NewImg = Me.MultiPage1.Pages(j - 1).Controls.Add("forms.image.1", "image" & j, True) 'change 1 by j??    
img = Files(j) here, i wanna write "for each Image on folder, but how?"     
NewImg.Visible = True     
NewImg.Left = 20     
NewImg.Top = 20 'and I need to increase the size     
NewImg.Picture = LoadPicture(img)   j = j + 1  
Debug.Print Files  
Files = Dir(, vbArchive) 
Wend
 
Upvote 0
Hi again, now I thing it's running. Thanks
I wanna let a sample here in a attachment, but I don't know how to do it
 
Upvote 0

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top