Roger
asked on
Excel vba automation: Assign macro to imported graphic
I assign a macro to a graphic that I have imported via xl_Ribbon/Insert/Picture :
ActiveSheet.Shapes.Range(A rray("Pict ure 3")).Select
Selection.OnAction = "tst"
BUT, if I import a graphic to an Excel cell, how do I identify that graphic so I can use vba to assign a macro to it?
With Range(Cells(rn.row + 1, 7), Cells(rn.row + 1, 1))
ActiveSheet.Shapes.AddPict ure "path\x.jpg", msoCTrue, msoTrue, .left, .top, -1, -1
ActiveSheet.Shapes(ActiveS heet.Shape s.Count).h eight = .height
End With
If you could briefly explain the principle of connecting input file name with
Shapes.Range, it would help me!
Thanks in anticipation
Kelvin
ActiveSheet.Shapes.Range(A
Selection.OnAction = "tst"
BUT, if I import a graphic to an Excel cell, how do I identify that graphic so I can use vba to assign a macro to it?
With Range(Cells(rn.row + 1, 7), Cells(rn.row + 1, 1))
ActiveSheet.Shapes.AddPict
ActiveSheet.Shapes(ActiveS
End With
If you could briefly explain the principle of connecting input file name with
Shapes.Range, it would help me!
Thanks in anticipation
Kelvin
ASKER
Not sure!
The sheet will contain potentially hundreds of rows with graphic icons, but each icon is added at a separate time, as new data rows are appended. I only need to assign the macro (once) to each new data row.
Also, what If I dont want that macro assigned to certain shapes on the ActiveSheet?
Thanks..
The sheet will contain potentially hundreds of rows with graphic icons, but each icon is added at a separate time, as new data rows are appended. I only need to assign the macro (once) to each new data row.
Also, what If I dont want that macro assigned to certain shapes on the ActiveSheet?
Thanks..
ASKER
would I be right in thinking that if I could:
Dim sh As Shape
set sh = ActiveSheet.Shapes.AddPict ure "path\x.jpg", msoCTrue, msoTrue, .left, .top, -1, -1
then sh.name would identify the shape for the assignment of the macro?
Kelvin
Dim sh As Shape
set sh = ActiveSheet.Shapes.AddPict
then sh.name would identify the shape for the assignment of the macro?
Kelvin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The text & code you wrote:
"Can't you just use this?
ActiveSheet.Shapes(ActiveS heet.Shape s.Count).O nAction = "tst" "
Kelvin then proposed what you claim to be the correct answer:
set sh = ActiveSheet.Shapes.AddPict ure "path\x.jpg", msoCTrue, msoTrue, .left, .top, -1, -1
then sh.name would identify the shape for the assignment of the macro?
You then write
"The code I posted would assign a macro to the most recently added shape, it would go straight after the code you posted. "
I dont think so, it would have assigned the macro to all shapes on active page!!
But thanks for the contribution.
Kelvin
"Can't you just use this?
ActiveSheet.Shapes(ActiveS
Kelvin then proposed what you claim to be the correct answer:
set sh = ActiveSheet.Shapes.AddPict
then sh.name would identify the shape for the assignment of the macro?
You then write
"The code I posted would assign a macro to the most recently added shape, it would go straight after the code you posted. "
I dont think so, it would have assigned the macro to all shapes on active page!!
But thanks for the contribution.
Kelvin
Kelvin
Not sure what you mean.
The first code I posted would only assign the macro to the most recent picture added.
This returns one shape/picture - the last member of the Shapes collection.
Not sure what you mean.
The first code I posted would only assign the macro to the most recent picture added.
This returns one shape/picture - the last member of the Shapes collection.
ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
ASKER
ok, thanks
Open in new window