Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8016803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:39:09+00:00 2026-06-04T20:39:09+00:00

I have a VBA toolbar that i have been working on. It has two

  • 0

I have a VBA toolbar that i have been working on. It has two buttons, and near the end of the process, it calls a python script.
What I want to do is depending on which of the two buttons is clicked, a certain part of the python script will run, so I want to pass a value that is linked to the button which is then sent to the python script and run.

How do I do this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:39:11+00:00Added an answer on June 4, 2026 at 8:39 pm

    You can pass command line options to the python script, just like you can with other command line programs. Depending on which button was pressed, pass different switches to your program.

    In your case, it may be simplest just to pass in one value on the command line depending on the button that was pressed and pick this from the sys.argv variable:

    import sys
    
    def fooClicked():
        # Stuff to do when Foo was clicked
    
    def barClicked():
        # Stuff to do when Bar was clicked
    
    button = sys.argv[1]
    if button == 'foo':
        fooClicked()
    elif button == 'bar':
        barClicked()
    

    (You could use a dict to look up methods but that may be too advanced, don’t know how comfortable you are with Python).

    So, if you call this script with python.exe H:\Report_v7.py foo the fooClicked function will be called.

    If this is going to grow to more than just two buttons, I’d use the optparse module to define your options and run different code paths depending on the options chosen.

    If you upgrade to Python 2.7, then use the new (better) argparse module instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vba userForm that has 36 buttons on it. I would like
I have a VBA script that inserts long strings into Excel cells. In some
I have a VBA script that imports a layout into an exsting drawing, its
I have some VBA code that opens a webpage, then calls a javascript function
I have created a VBA script that detects a number and shows a colour
Using Excel 2002 and have a VBA app that has some UserForms. The main
I have VBA code that takes my data on the master worksheet and puts
I have a VBA macro that copies rows from one worksheet into another based
I have a VBA code that creates a file and need to have an
I have a VBA Word Macro that gets words from .txt list and color

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.