Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

macro links broken

Status
Not open for further replies.

maximas

Programmer
Nov 29, 2002
40
US
I have a workbook with 3 macros A B C. I created a customized toolbar for my macros and assign a macro name with the macros in only this workbook. I save it. It runs, but If I create a duplicate workbook, just in case I trashed the workbook. I try to run the macros in the original one, it will not run! How Come???
 
Have a look at the recent thread started by smooveb - Excel - attaching a button for macro to particular file.

I poste some sample code there to reassign the buttons to the correct set up. As you have 3 macros, something like the following might help
Code:
Dim cBar As CommandBar
Set cBar = CommandBars("CustomBar")
For Each Control In cBar.Controls
    Select Case Control.Index
        Case 1
            Control.OnAction = "Macro1"
        Case 2
            Control.OnAction = "Macro2"
        Case 3
            Control.OnAction = "Macro3"
    End Select
Next
A.C.
 
I look at the previous post, he is having the same problem
Run-time error '91': Object variable or With block variable not set.
Private Sub Workbook_Open()
Dim cBar As CommandBar
Dim cbar2 As CommandBar
Set cBar = CommandBars("Engineering") ---problem line
Set cbar2 = CommandBars("Start Macro") --problem line
For Each Control In cBar.Controls
Select Case Control.Index
Case 1
Control.OnAction = "Add"
Case 2
Control.OnAction = "Delete"
Case 3
Control.OnAction = "undo"
Case 4
Control.OnAction = "Adjustment"
Case 5
Control.OnAction = "New_Payment_Request"
Case 6
Control.OnAction = "stopmacro"
Case 7
Control.OnAction = "loadchangeorders"
Case 8
Control.OnAction = "loadholdbacks"
Case 9
Control.OnAction = "loadsettlement"
End Select
Next
cbar2.Controls(1).OnAction = "startmacro"
End Sub

toolbar:
Engineering
Add Delete Undo Adjust New .........
 
OK, Maximas.

The error you describe arises when you palce the code in the ThisWorkbook or one of the sheet objects. Place the code in a general module and call it from the Thisworkbook module if needed.

A.C.
 
call me dumb, but i'm not getting it! I have put the code in this workbook -> (General) (Declarations), but the macros links are still link back to the previous one. For example. I have a excel file with macros in c drive and the macros are link to the file name A. when I copy and then paste the file in d drive, the macros are linked back to c drive, file name A and the macros name. How to fix this problem! it's killing me!

 
I will not call you dumb, but a general module is not part of a ThisWorkbook module. You get a general module by using (in the VB editor environment) Insert, Module.

Insert the code in that module, and if required call it from the ThisWorkbook module.

Please do not think you are in anyway dumb. It would be dumb not to ask.

A.C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top