ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   INSERT PICTURE IN MACRO (https://www.excelbanter.com/excel-programming/328046-insert-picture-macro.html)

glenn

INSERT PICTURE IN MACRO
 
oK i WANT TO RY THIS AGAIN. i AM A NOVICE SO PLEASE HELKP ME UNDERSTAND.
sorry...I do know how to record a macro but the help is needed to:

I want to build a macro that will allow a picture,clipart, to be inserted on
one worksheet if in another worksheet a cell ---let's say is true. How to do
this??? Does the clipart have to be on the page when recording the macro???
What is the programing to record??? Lets's say that :

In worksheet 1 that B3="3"
Macro would then insert the clipart in worksheet2 in a given spot because
B3 in worksheet one was equal to "3"

Hope I am making since:)
Glenn


Greg Wilson

INSERT PICTURE IN MACRO
 
My example uses the GetOpenFileName method to select the picture and includes
a Data Validation dropdown list to select a filter. To set this up:
1) On Sheet1 in cell D1 through D9 paste the following filter types:
..bmp
..emf
..gif
..jfif
..jpe
..jpg
..jpeg
..png
..wmf

2) Select cell A1 on Sheet1 and apply data validation to this cell:
i) Select Data from the main toolbar
ii) Select Validation...
iii) Select "List" from the "Allow:" dropdown list
iv) Ensure that the In-cell dropdown checkbox item is selected.
v) Click inside the "Source:" window and then select the range D1:D9 or
type in:
"=$D$1:$D$9".
vi) Clik OK
If the above has been done correctly, when you select cell A1, a dropdown
list should appear allowing you to select from the filter list in D1:D9.

3) In cell B1 enter the header "Top"
4) In cell C1 enter the header "Left"
5) In cell B2 enter a number(e.g. 4).
6) In cell C2 enter a number (e.g. 2).
7) Paste the following macro to a standard module.
8) Run the macro and select the desired picture. The picture will be pasted
to the top-left corner of cell B4 of Sheet2 if the above values in B2 and C2
are used. Note that the picture size keys off of the height of the
destination cell in Sheet2. These cells should be sized appropriately.

Sub InsertPict()
Dim txt As String
Dim PName As Variant
Dim P As Picture
Dim ws1 As Worksheet, ws2 As Worksheet
Dim R As Single
Dim rw As Long, col As Long
Dim c As Range

Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
txt = "*" & ws1.Range("A1").Value
rw = ws1.Range("B2").Value
col = ws1.Range("C2").Value
If Val(rw) = 0 Or Val(col) = 0 Then Exit Sub
Set c = ws2.Cells(rw, col)
With Application
PName = .GetOpenFilename("Picture files (" & txt & ")," & txt)
If PName = False Then Exit Sub
.ScreenUpdating = False
Set P = ws2.Pictures.Insert(PName)
R = P.Height / P.Width
P.Left = c.Left: P.Top = c.Top
P.Height = c.Height: P.Width = P.Height / R
.ScreenUpdating = True
End With
End Sub

Hope I didn't make a mistake in the post. I'm sick today and am having
trouble thinking clearly.

Regards,
Greg

"Glenn" wrote:

oK i WANT TO RY THIS AGAIN. i AM A NOVICE SO PLEASE HELKP ME UNDERSTAND.
sorry...I do know how to record a macro but the help is needed to:

I want to build a macro that will allow a picture,clipart, to be inserted on
one worksheet if in another worksheet a cell ---let's say is true. How to do
this??? Does the clipart have to be on the page when recording the macro???
What is the programing to record??? Lets's say that :

In worksheet 1 that B3="3"
Macro would then insert the clipart in worksheet2 in a given spot because
B3 in worksheet one was equal to "3"

Hope I am making since:)
Glenn



All times are GMT +1. The time now is 06:01 PM.

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