Results 1 to 10 of 10

Thread: change macro name with vba?

  1. #1
    Member
    Join Date
    Jun 10
    Posts
    62

    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":



    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!

  2. #2
    Fanatic Member
    Join Date
    Oct 08
    Location
    Midwest Region, United States
    Posts
    988

    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?

  3. #3
    Member
    Join Date
    Jun 10
    Posts
    62

    Re: change macro name with vba?

    Quote Originally Posted by vbfbryce View Post
    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...

  4. #4
    Fanatic Member
    Join Date
    Oct 08
    Location
    Midwest Region, United States
    Posts
    988

    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

  5. #5
    Member
    Join Date
    Jun 10
    Posts
    62

    Re: change macro name with vba?

    Quote Originally Posted by vbfbryce View Post
    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)...

  6. #6
    Member
    Join Date
    Jun 10
    Posts
    62

    Re: change macro name with vba?

    nobody?

  7. #7
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,524

    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
    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

  8. #8
    Member
    Join Date
    Jun 10
    Posts
    62

    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...



    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?

  9. #9
    Fanatic Member
    Join Date
    Oct 08
    Location
    Midwest Region, United States
    Posts
    988

    Re: change macro name with vba?

    Does my attached image portray what you want to change via code?
    Attached Images Attached Images  

  10. #10
    Member
    Join Date
    Jun 10
    Posts
    62

    Re: change macro name with vba?

    Quote Originally Posted by vbfbryce View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •