Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Macro doesn't perform correctly when using right click menu

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Macro doesn't perform correctly when using right click menu

Thanks for the reply.

There are a couple of things I didn't realize. The shapes
(pictures) are actually groupobjects. What I'm
experiencing is when I use the INSERT key it seems to
think that the shape on the sheet is a groupobject but
when I use the shapes right click menu it thinks that the
existing shape is a drawingobject and the code does not
function the same due to the differences between the two
different types.

It is a bit difficult to send an example of the code but I
will try to condense it down to something understandable.

David

Sub CompInsert()
Dim CompName As String

If TypeName(Selection) = "Picture" Then
SelName = Selection.Name
CompName = ActiveSheet.Shapes(SelName).ParentGroup.Name
ElseIf TypeName(Selection) = "GroupObject" Then
CompName = Selection.Name
End If

'Determine top for new inserted shape
InsTop = ActiveSheet.Shapes(CompName).Top + _
ActiveSheet.Shapes(CompName).Height

'Figure out what the number of the selected shape is
DashPos = InStr(1, CompName, "_", vbTextCompare)
CompNum = Right(CompName, Len(CompName) - DashPos)
Num = CInt(CompNum)

SendKeys "{ESC}", True 'Cells(1, 1).Select

'Determine location for new shape description
NewRow = Worksheets("Datasheet").Range("Description_" &
Num).Row

'Figure out how many grouped shapes on the on the
worksheet alread
Call Counter(i)

'Group shapes below selection
If i 0 Then
z = 0
For Each Shp In ActiveSheet.Shapes
DashPos = InStr(1, Shp.Name, "_", vbTextCompare)
CompNumTest = Right(Shp.Name, Len(Shp.Name) -
DashPos)
NumTest = CInt(CompNumTest)
If InStr(1, Shp.Name, "Component", vbTextCompare)
And NumTest < Num Then '
Shp.Select False
z = z + 1
End If
Next
End If

If z 1 Then
Selection.ShapeRange.Group.Select
Selection.Name = "Temp1"
ElseIf z = 1 Then
'It seems to have a problem with the drawingobject versus
groupobject thing at this point as I get the message that
the object does not support this property at this location
when using the right mouse button method.
Selection.Name = "Temp2"
End If

etc. ....



-----Original Message-----
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
.

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Value won't show correctly in cell unless I double click formula, Marc Z Excel Discussion (Misc queries) 1 November 15th 07 09:56 PM
Can I add a Macro to right-click Menu? Ed Excel Discussion (Misc queries) 8 October 11th 06 02:43 PM
adding macro to right mouse click menu JimB Excel Discussion (Misc queries) 1 October 31st 05 03:37 PM
right click menu reset? danped Excel Programming 1 July 14th 04 12:16 PM
Adding menu to the mouse right click pop-up menu Jack Excel Programming 1 February 12th 04 05:23 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"