Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Command Button (Excel VBA)

    I have a file Requistion.xlt with a Sub Macro 1() stored as module 1. I would like someone to click the template to create a new file, change the file name (very important as this info is stored) and then click a command button to run the marco. I've tried to use the code below to do what I want but it will not work. Thanks.

    Private Sub SendToDatabase_Click()

    Dim fileName

    fileName = ActiveWorkbook.Name
    Application.Run "fileName!Macro1"

    End Sub

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command Button (Excel VBA)

    If Macro1 is in the template file, then all you should need is:

    <pre> Call Macro1
    </pre>


    If you really do need to use the Run method, then the correct syntax is:

    <pre> Application.Run fileName & "!Macro1"
    </pre>

    Legare Coleman

  3. #3
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command Button (Excel VBA)

    Thank you, Call Marco1 worked

Posting Permissions

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