+ Reply to Thread
Results 1 to 7 of 7

2 macros in one button?

  1. #1
    Registered User
    Join Date
    12-11-2012
    Location
    bristol
    MS-Off Ver
    Excel 2007
    Posts
    40

    Question 2 macros in one button?

    Hello,

    Is it possible to assign 2 macros to 1 button? The macros I want to combine are:

    Sub Invoicelog_Button2_Click()

    Dim fname
    fname = "My path " & Format(Now, "dd mmm yy") & ".xls"
    ActiveWorkbook.SaveCopyAs Filename:=fname

    End Sub

    And:

    Sub Invoicelog_Button2_Click()

    Range("K3").Value = Now()

    End Sub

    Now, it gives me an error: Ambigious name detected

    I am new to VBA, can anyone help me?

    Thanks
    Last edited by hond; 12-11-2012 at 07:37 AM.

  2. #2
    Registered User
    Join Date
    12-20-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: 2 macros in one button?

    Im not great with VBA but would you not be able to create a new macro to call the two processes you want to run, and then assign that macro to the button?

    Sub Button_Click()

    Call Macro1

    Call Macro 2

    End Sub



    I might be way off of the mark, but give it a try?

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: 2 macros in one button?

    Hi hond,

    Welcome to the forum!!

    Please make sure you wrap all code with the appropriate tags as I have done.

    You could have two macros from the same button if your macro actually changed the button name so it could distinguish which piece of code to run. The problem above is that you cannot have the same macro name twice in the same workbook.

    You could simply combine the two statements into one macro like so:

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: 2 macros in one button?

    Why not just merge the two macros.


    PS. that's what Trebor76 just said
    Last edited by rollis13; 12-11-2012 at 06:37 AM.

  5. #5
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: 2 macros in one button?

    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  6. #6
    Registered User
    Join Date
    12-11-2012
    Location
    bristol
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: 2 macros in one button?

    Thank you all!

    How do I mark this as solved?

    P.s. just learned VBA today so I didn't know how to merge macros.

  7. #7
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: 2 macros in one button?

    You are welcome.

    See at Trebor's or my signature to see how you can mark this as SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1