View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson[_4_] Greg Wilson[_4_] is offline
external usenet poster
 
Posts: 218
Default Macro doesn't perform correctly when using right click menu

David,

You need to post your code or relevant portions of it.

The popup commandbar you get when you right-click a
picture is called the "Pictures Context Menu" while the
one you get when you right-click a shape from the Drawing
toolbar is called "Shapes". I did not replicate your
problem as I understood it in my experiments. I
successfully conducted the experiments using both
the "Pictures Context Menu" popup commandbar (see below)
and the "Shapes" popup commandbar. Changing the Pict and
NewPict type declarations to Picture instead of Variant
did not cause a problem if the items were in fact pictures.

The code I used follows:

Sub XXX()
Dim Ctl As CommandBarControl
Dim CB As CommandBar
With Application
Set CB = .CommandBars("Pictures Context Menu")
CB.Reset
Set Ctl = CB.Controls.Add(Temporary:=True)
Ctl.OnAction = "InsertPict"
Ctl.Caption = "Insert picture"
.OnKey "{INSERT}", "InsertPict"
End With
End Sub

Sub InsertPict()
Dim Pict As Variant, NewPict As Variant
Dim F As String
Set Pict = Selection
F = "C:\Documents and Settings\greg\" & _
"My Documents\My Pictures\Sample.jpg"
Set NewPict = ActiveSheet.Pictures.Insert(F)
With NewPict
.Top = Pict.Top + Pict.Height + 5
.Left = Pict.Left
End With
End Sub

Regards,
Greg


-----Original Message-----
I have a macro that I have tied to execute when the

INSERT
key is pressed on the keyboard that I have also tried to
have run by creating a menu item on the right click menu
for a shape. The right click menu method does not give me
the same result as the INSERT key method.

Essentially the macro is run once a picture on the
worksheet is selected by first selecting the picture with
a left mouse click and then pressing the INSERT key. The
macro then places another picture immediately below the
selected picture.

If I select the picture using the left mouse click and
then press the right mouse button and select the insert
menu item I created (that calling the INSERT key macro)
the new picture does not get inserted below the original
picture but rather in another location or I get a message
telling that the object does not support that property.

The only thing I can think is happening is that by making
the right mouse selection I somehow am loosing "focus" of
the original picture which then messes things up.

Has anyone experienced a similar situation???

David
.