change macro name with vba?
Hi all,
I have 3 macro's to create the menu in my access-form.
MACRO 1:
DoCmd.AddMenu "&File", "M_File", "File"
DoCmd.AddMenu "&Edit", "M_Edit", "Edit"
MACRO "M_FILE":
http://i39.tinypic.com/2edtkwo.jpg
Now I want to change the "macro name" with vba... I cannot find how.
I tried to replace "copy" by "=mycopyfunction()", but this does not work.
How can I replace the macro name (the name displayed in my menu) by a name given by a vba function?
thank you!
Re: change macro name with vba?
Do you have a requirement to use vba code, or can you use another macro to do this?
For example, I used the "CopyObject" action, which requires a source name and a new name. Then I used the "DeleteObject" action to delete the old macro.
Would this work for you, or does the user provide the new name at run time?
Re: change macro name with vba?
Quote:
Originally Posted by
vbfbryce
Do you have a requirement to use vba code, or can you use another macro to do this?
For example, I used the "CopyObject" action, which requires a source name and a new name. Then I used the "DeleteObject" action to delete the old macro.
Would this work for you, or does the user provide the new name at run time?
I prefer vba code, because the name depends indeed on the user input...
Re: change macro name with vba?
Does this work?
Code:
Sub renameMac()
Dim macCount As Integer
Dim i As Integer
Dim newName As String
newName = InputBox("Enter new name for macro")
macCount = CurrentProject.AllMacros.Count
For i = 1 To macCount
If CurrentProject.AllMacros(i).Name = "macOriginal" Then
DoCmd.Rename newName, acMacro, "macOriginal"
Exit Sub
End If
Next i
End Sub
Re: change macro name with vba?
Quote:
Originally Posted by
vbfbryce
Does this work?
Code:
Sub renameMac()
Dim macCount As Integer
Dim i As Integer
Dim newName As String
newName = InputBox("Enter new name for macro")
macCount = CurrentProject.AllMacros.Count
For i = 1 To macCount
If CurrentProject.AllMacros(i).Name = "macOriginal" Then
DoCmd.Rename newName, acMacro, "macOriginal"
Exit Sub
End If
Next i
End Sub
Hi,
This does work but renames the macro. I need to rename the "macro name" field in the macro (when goïng to edit mode)...
Re: change macro name with vba?
Re: change macro name with vba?
look in the tutorial in the faq thread at the top of this forum, for working with commandbars, which includes commandbarbuttons
Re: change macro name with vba?
Hi,
I already found the tutorial for working with commandbars, but i cannot find how to include all the things that are in the macro...
http://i42.tinypic.com/o8v1ns.jpg
How do I include "close", "runcommand(print)", "runcode(repair & compact)", "openform", ... in the commandbars?
And how do I include "copy", "paste", "edit"...
With a macro, this is very simple, is this also possible in commandbars without writing a lot of code?
1 Attachment(s)
Re: change macro name with vba?
Does my attached image portray what you want to change via code?
Re: change macro name with vba?
Quote:
Originally Posted by
vbfbryce
Does my attached image portray what you want to change via code?
No, I do not want to change the macro that needs to run.
I want to change the name that is displayed in the menu