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?
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...
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
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)...
look in the tutorial in the faq thread at the top of this forum, for working with commandbars, which includes commandbarbuttons
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
I already found the tutorial for working with commandbars, but i cannot find how to include all the things that are in the macro...
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?