View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Can't change macro assigned to drawing object

If I follow you have two workbooks each with similar objects with their
OnAction properties set to trigger similarly named macros in their own
workbook.

Are you absolutely sure the named macros exist in both workbooks. If not, if
you try to qualify the onaction to a non existent macro in own workbook it
will continue to point to the macro in the other workbook which presumably
does exist. Do you filter the macros in the dialog to show only those in
ThisWorkbook.

Or perhaps Excel is getting confused with similarly named macros in
different workbooks.
This should relink to macros in own workbook or flag a problem if the macro
doesn't exist in own workbook (the macro onaction will remain unchanged).

Sub ReAssignMacros()
Dim nPos As Long
Dim sMacro As String
Dim sOrig As String
Dim sMacroPrefix As String
Dim shp As Shape

sMacroPrefix = "'" & ActiveWorkbook.Name & "'!"

For Each shp In ActiveSheet.Shapes
sMacro = "": sOrig = "": nPos = 0
sMacro = shp.OnAction
sOrig = sMacro
If Len(sMacro) Then

nPos = InStr(1, sMacro, "!")
If nPos Then
sMacro = Right(sMacro, Len(sMacro) - nPos)
End If

On Error Resume Next
sMacro = sMacroPrefix & sMacro
shp.OnAction = sMacro

If Err.Number Then
Debug.Print shp.Name, Err.Description
End If

On Error GoTo 0
Else
sOrig = "no macro"
End If

Debug.Print shp.Name, shp.OnAction, sOrig
Next
End Sub

Regards,
Peter T




"MarquisB" wrote in message
...
Hi All:

I'm writing an app under Excel 9 and Windows 98SE. I have several drawing
objects on the sheet, and a unique macro is assigned to each object. I

also
have two workbooks open simultaneously. The problem is that I can't change
the macro assignments. For some reason Excel is trying to run a macro with
the "right" name but under the "wrong" workbook. I've tried right-clicking

on
the drawing object and repeating the "assign" command but Excel leaves the
assignment unchanged. I've tried it with the sheets and workbooks

protected
and un-protected, with the second workbook open and closed, with the

target
macros in different code modules, etc. I've tried selecting the macro from
the list in the Assign Macro box, typing it myself (qualified and
un-qualified), recording a new one and replacing the code, etc. Nothing

seems
to work. Anybody have any idea what I'm doing wrong? Thanks...

--
Mark B.
Hampstead, NC USA

"Perpetual optimism is a force multiplier."
- Gen. Colin Powell