Macros renaming with new workbook created from an .xlam add-in

rdetreville

New Member
Joined
Jul 23, 2014
Messages
38
Hello,

I've created a .xlam add-in tool that generates a report from a number of sources. It gathers data from various sources and then populates a new workbook "Book1". Then, it copies the hidden worksheet "MENU" from itself (the .xlam add-in file) which is a user interface menu for navigating the report. This MENU worksheet has VBA coding written in it. There are a number of textbox objects on this menu sheet which need to connect to these macros. Unfortunately, the Macro links won't stick because the macro name changes every time I run the add-in due to the sheet being renamed. I get the following error:

k00wv5.jpg


Even though the sheet is called "MENU", the macro names keep renaming themselves to the sheet number. For example, the sheet is now called Sheet3:

o0z7ef.jpg




I've tried the following "worksheetactivate" code built into this "MENU" worksheet, but it doesn't work as the sheet number keeps changing. How can I link these text boxes to the correct macros? Is there a code that can create a new macro from string data and set it as a macro in a new module? Can I rename the sheet number using VBA? I tried to record a macro to rename the (Name) to Sheet99, but it didn't record anything.

Thanks for your help.

Richard


Code:
Private Sub Worksheet_Activate()

With Sheets("Menu")
.Shapes("Menubar").OnAction = "MENU.Menubar_Click"
.Shapes("butoverall").OnAction = "Sheet8.butoverall_Click"
.Shapes("butundis").OnAction = "Sheet8.butundis_Click"
.Shapes("butdisun").OnAction = "Sheet8.butdisun_Click"
.Shapes("butbusy").OnAction = "Sheet8.butbusy_Click"
.Shapes("butnotbusy").OnAction = "Sheet8.butnotbusy_Click"
.Shapes("butpmdate").OnAction = "Sheet8.butpmdate_Click"
.Shapes("butrevrec").OnAction = "Sheet8.butrevrec_Click"

.Shapes("trackeropen1").OnAction = "Sheet8.trackeropen1_Click"
.Shapes("trackeropen2").OnAction = "Sheet8.trackeropen2_Click"
.Shapes("trackeropen3").OnAction = "Sheet8.trackeropen3_Click"
End With


End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Is there any way I can get the following to "ActiveWorkbook?"

Code:
Private Sub Worksheet_Activate()

With Sheets("Menu")
.Shapes("Menubar").OnAction = "Sheet8.Menubar_Click"


Or a way I can rename a Macro?
 
Upvote 0
and I found the following, though this doesn't help since I don't know what the CodeName of the sheet will be each time it's created:

Code:
Sub AChangeOfName()
ThisWorkbook.VBProject.VBComponents("Sheet1").Name = "Mudface"
'change the codename for Sheet1 to Mudface
End Sub
 
Upvote 0
Going to try this...
Code:
Dim vbComp As Object
    Dim fName As String
        fName = "AddModule.bas"
        Application.VBE.ActiveVBProject.VBComponents("Modu  leX").Export fName
        Workbooks("WBToUpdate.xls").Activate
        ActiveWorkbook.VBProject.VBComponents.Import fName
    End Sub
 
Upvote 0
I think I got it to work! I love answering my own questions haha ;)

I put all the macros I need in a module called "CodeMove" and used the macro below to move that module from the .xlam file to my newly created workbook. I will test and report back.

Code:
Sub movecodes()
Dim vbComp As Object
Dim fName As String
fName = "CodeMove"
Application.VBE.ActiveVBProject.VBComponents("CodeMove").Export fName
ActiveWorkbook.VBProject.VBComponents.Import fName

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,427
Messages
6,119,419
Members
448,895
Latest member
omarahmed1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top