ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loading Pictures in Image box (https://www.excelbanter.com/excel-programming/350457-loading-pictures-image-box.html)

Troubled User

Loading Pictures in Image box
 
I have named a file path and file location in VB to locate a particular
photo. As the user selects different items from a droplist the file path and
name change. In the change event on that droplist I need to know how to call
the load event for the Image object. So far I have tried:

Image1.Picture = LoadPicture(PictureFileName1) - Where PictureFileName is my
path and file name as well as hard coding to

Image1.Picture = LoadPicture("e:\monthlyreport\Photo1.bmp")

I don't understand the correct syntax to change the picture file.

Please help. Thank you!



Tom Ogilvy

Loading Pictures in Image box
 
Private Sub UserForm_Initialize()
Me.Image1.Picture = LoadPicture("c:\images.jpg")

End Sub

worked fine for me. Using a variable to hold "C:\Imgages.jpg" would work as
well.

--
Regards,
Tom Ogilvy


"Troubled User" wrote in message
...
I have named a file path and file location in VB to locate a particular
photo. As the user selects different items from a droplist the file path

and
name change. In the change event on that droplist I need to know how to

call
the load event for the Image object. So far I have tried:

Image1.Picture = LoadPicture(PictureFileName1) - Where PictureFileName is

my
path and file name as well as hard coding to

Image1.Picture = LoadPicture("e:\monthlyreport\Photo1.bmp")

I don't understand the correct syntax to change the picture file.

Please help. Thank you!





Leith Ross[_464_]

Loading Pictures in Image box
 

Hello Troubled User,

First you need to place your code in the Click() event, not th
Change() event. I'm assuming you know how to return the user'
selection from the ComboBox, but I will include the code just in case.

*Example*:
Sub ComboBox1_Click()

With ComboBox1
ImageList1.Picture = LoadPicture(.List(.ListIndex))
End With

End Sub

Change "ComboBox1" to the name of your control. The LoadPictur
FileName argument is a string. The string can be a literal (i
quotes), or a variable such as a Variant or String type.

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=50141


Troubled User

Loading Pictures in Image box
 
Tom, Here is the entire code. I got invalid use of the Me keyword using your
suggestion, so based on what was written by Leith I tried simply
'Image1.Picture = LoadPicture(PictureFileName1) and got a Object required
error.

Any help is appreciated. Thank you.

WB

Sub NewInserttoImageBox()

Dim PictureFileName1 As Variant
Set PictureFileName1 = Worksheets("PropertyList").Range("J3")

Application.ScreenUpdating = False

Worksheets("CoverPage").Select

'Me.Image1.Picture = LoadPicture(PictureFileName1)
'This returned Invalid Use of Me Keyword

'Image1.Picture = LoadPicture(PictureFileName1)
'Returns Runtime Error 424 - Object Required

Worksheets("Input").Select

Application.ScreenUpdating = True

"Tom Ogilvy" wrote:

Private Sub UserForm_Initialize()
Me.Image1.Picture = LoadPicture("c:\images.jpg")

End Sub

worked fine for me. Using a variable to hold "C:\Imgages.jpg" would work as
well.

--
Regards,
Tom Ogilvy


"Troubled User" wrote in message
...
I have named a file path and file location in VB to locate a particular
photo. As the user selects different items from a droplist the file path

and
name change. In the change event on that droplist I need to know how to

call
the load event for the Image object. So far I have tried:

Image1.Picture = LoadPicture(PictureFileName1) - Where PictureFileName is

my
path and file name as well as hard coding to

Image1.Picture = LoadPicture("e:\monthlyreport\Photo1.bmp")

I don't understand the correct syntax to change the picture file.

Please help. Thank you!






Tom Ogilvy

Loading Pictures in Image box
 
Me was particular to the userform which I was using to illustrate that this
is the correct construct.

in your case, I assume Image1 is on the worksheet worksheets("Coverpage")

so replace
'Image1.Picture = LoadPicture(PictureFileName1)

with

Worksheets("CoverPage").Image1.Picture = _
LoadPicture(PictureFileName1)


or qualify it with a reference to the sheet on which it is located.

--
Regards,
Tom Ogilvy



"Troubled User" wrote in message
...
Tom, Here is the entire code. I got invalid use of the Me keyword using

your
suggestion, so based on what was written by Leith I tried simply
'Image1.Picture = LoadPicture(PictureFileName1) and got a Object required
error.

Any help is appreciated. Thank you.

WB

Sub NewInserttoImageBox()

Dim PictureFileName1 As Variant
Set PictureFileName1 = Worksheets("PropertyList").Range("J3")

Application.ScreenUpdating = False

Worksheets("CoverPage").Select

'Me.Image1.Picture = LoadPicture(PictureFileName1)
'This returned Invalid Use of Me Keyword

'Image1.Picture = LoadPicture(PictureFileName1)
'Returns Runtime Error 424 - Object Required

Worksheets("Input").Select

Application.ScreenUpdating = True

"Tom Ogilvy" wrote:

Private Sub UserForm_Initialize()
Me.Image1.Picture = LoadPicture("c:\images.jpg")

End Sub

worked fine for me. Using a variable to hold "C:\Imgages.jpg" would

work as
well.

--
Regards,
Tom Ogilvy


"Troubled User" wrote in

message
...
I have named a file path and file location in VB to locate a

particular
photo. As the user selects different items from a droplist the file

path
and
name change. In the change event on that droplist I need to know how

to
call
the load event for the Image object. So far I have tried:

Image1.Picture = LoadPicture(PictureFileName1) - Where PictureFileName

is
my
path and file name as well as hard coding to

Image1.Picture = LoadPicture("e:\monthlyreport\Photo1.bmp")

I don't understand the correct syntax to change the picture file.

Please help. Thank you!








Troubled User

Loading Pictures in Image box
 
Thanks a bunch. Works perfectly!!!!!! You made my day!

"Tom Ogilvy" wrote:

Me was particular to the userform which I was using to illustrate that this
is the correct construct.

in your case, I assume Image1 is on the worksheet worksheets("Coverpage")

so replace
'Image1.Picture = LoadPicture(PictureFileName1)

with

Worksheets("CoverPage").Image1.Picture = _
LoadPicture(PictureFileName1)


or qualify it with a reference to the sheet on which it is located.

--
Regards,
Tom Ogilvy



"Troubled User" wrote in message
...
Tom, Here is the entire code. I got invalid use of the Me keyword using

your
suggestion, so based on what was written by Leith I tried simply
'Image1.Picture = LoadPicture(PictureFileName1) and got a Object required
error.

Any help is appreciated. Thank you.

WB

Sub NewInserttoImageBox()

Dim PictureFileName1 As Variant
Set PictureFileName1 = Worksheets("PropertyList").Range("J3")

Application.ScreenUpdating = False

Worksheets("CoverPage").Select

'Me.Image1.Picture = LoadPicture(PictureFileName1)
'This returned Invalid Use of Me Keyword

'Image1.Picture = LoadPicture(PictureFileName1)
'Returns Runtime Error 424 - Object Required

Worksheets("Input").Select

Application.ScreenUpdating = True

"Tom Ogilvy" wrote:

Private Sub UserForm_Initialize()
Me.Image1.Picture = LoadPicture("c:\images.jpg")

End Sub

worked fine for me. Using a variable to hold "C:\Imgages.jpg" would

work as
well.

--
Regards,
Tom Ogilvy


"Troubled User" wrote in

message
...
I have named a file path and file location in VB to locate a

particular
photo. As the user selects different items from a droplist the file

path
and
name change. In the change event on that droplist I need to know how

to
call
the load event for the Image object. So far I have tried:

Image1.Picture = LoadPicture(PictureFileName1) - Where PictureFileName

is
my
path and file name as well as hard coding to

Image1.Picture = LoadPicture("e:\monthlyreport\Photo1.bmp")

I don't understand the correct syntax to change the picture file.

Please help. Thank you!










All times are GMT +1. The time now is 07:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com