How to insert picture form from worksheet

Hiffny
06-29-2010, 10:16 PM
Dear all,

I would like your help in showing me how to add a picture to the form which the picture not link to external source like in c drive but instead the picture i save inside the excel worksheet, same file with the form.

Any idea?

Appreciated your reply,

Hiffny

JONvdHeyden
06-30-2010, 07:30 AM
Hello Hiffny

You are likely to need to tweak this to get the exact size metrics right, but something along the lines of:

Public Sub PicFromWsToForm()
Dim cht As ChartObject, shp As Shape
Dim strPic As String

strPic = "C:\TempImage.gif"
Set shp = Sheet1.Shapes(1) 'assumes 1st shape in sheet is desired picture

'paste the pic into a chart and then export chart as image file
With Sheet1.ChartObjects.Add(1, 1, shp.Width, shp.Height)
shp.Copy
With .Chart
.Paste
With .ChartArea
.Border.LineStyle = 0
.Interior.ColorIndex = xlNone
End With
.Export strPic
End With
.Delete
End With

'insert pic into form
With UserForm1
With .Image1
.Picture = LoadPicture(Filename:=strPic)
.Width = shp.Width
.Height = shp.Height
End With
.Show
End With

Kill PathName:=strPic 'delete the image from disk
End Sub

Hiffny
06-30-2010, 09:16 PM
Thank you for your reply Jonvdheyden,

Is there any way you can help upload a working sample for the above method?

I can study it from there.

JONvdHeyden
07-01-2010, 01:23 AM
Hi

I've attached XL03 xls file as an example.

Hiffny
07-02-2010, 12:31 AM
Dear JONvdHeyden,

Thank you for that. However what i try to do is when i open up the form, the form automatically show the picture without clicking. the form in the other hand were link to the toolbar.

You know how to do so?

JONvdHeyden
07-02-2010, 01:26 AM
Hi Hiffny

I don't understand. How exactly do you want this to work?

Hiffny
07-02-2010, 03:11 AM
Here what i want to do.

I create a userform and all it code and function into file A(for example)

Then i link up the userform with the toolbar using macro as per step 1 picture.

When i click on one of the form, the form will show up like in the step 2.

The form that come out with the picture on it.

The picture then is set to taken from the sheet(either hidden or not).

That i looking for.

Can you help?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum