+ Reply to Thread
Results 1 to 10 of 10

how to launch excel macro from desktop

  1. #1
    Registered User
    Join Date
    10-24-2007
    Posts
    37

    Exclamation how to launch excel macro from desktop

    Hi folks,
    I have a macro that works fine in a worksheet in Excel. Instead of opening the Excel file and click on the macro, I want to place it a shortcut key on the desktop. If users click this buttion, that button should open the Excel file and start the embedded macro automatically and close the files at the end.
    Is it possible using VB code? I searched the forum, but unable to find similar references.
    Any help/reference is appreciated.
    thanks

  2. #2
    Valued Forum Contributor Excelenator's Avatar
    Join Date
    07-25-2006
    Location
    Wantagh, NY
    Posts
    333
    You can accomplish this by inserting the name of the macro you want to run when the file opens into the Workbook_Open event in the This Workbook object in the VBE. (One more time in English???)

    If your macro that you want to run is called "MacroStart" go to the VBE (Visual Basic Editor ... see signature below for instructions), double click the "This Workbook" object, in the drop down box at the top of the screen that has "General" in it select "Workbook". The "Workbook_Open" sub will be automatically populated for you as below. Insert the name of your macro in there.

    Please Login or Register  to view this content.
    Be sure to include code in your macro that will save the file (if that is what you want it to do) and then close the file. Now any shortcuts (to place a shortcut to the file on your desktop, right click the file and select "send to desktop (create shortcut)") on the desktop to this file will run your code upon opening the file and then save and close itself.
    ---------------------------------------------------
    ONLY APPLIES TO VBA RESPONSES WHERE APPROPRIATE
    To insert code into the VBE (Visual Basic Editor)
    1. Copy the code.
    2. Open workbook to paste code into.
    3. Right click any worksheet tab, select View Code
    4. VBE (Visual Basic Editor) opens to that sheets object
    5. You may change to another sheets object or the This Workbook object by double clicking it in the Project window
    6. In the blank space below the word "General" paste the copied code.

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486
    Quote Originally Posted by mixel
    Hi folks,
    I have a macro that works fine in a worksheet in Excel. Instead of opening the Excel file and click on the macro, I want to place it a shortcut key on the desktop. If users click this buttion, that button should open the Excel file and start the embedded macro automatically and close the files at the end.
    Is it possible using VB code? I searched the forum, but unable to find similar references.
    Any help/reference is appreciated.
    thanks
    Do you want the workbook saved before it closes, and how do you want it saved?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    A macro cannot be run without the workbook that contains it being open and macros enabled.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486
    A macro cannot be run without the workbook that contains it being open and macros enabled.
    __________________
    Hope that helps.

    RoyUK
    Placing a shortcut icon on the desktop to open a specific workbook answers the first part of the question, when clicking that Icon to open that workbook, you are in fact running a specific macro.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by davesexcel
    Placing a shortcut icon on the desktop to open a specific workbook answers the first part of the question, when clicking that Icon to open that workbook, you are in fact running a specific macro.
    Agreed, but the user will need to Enable macros and I think from the original question that the OP thinks to automatically run the macro from the Desktop, not have to open the workbook.

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486
    Quote Originally Posted by royUK
    Agreed, but the user will need to Enable macros and I think from the original question that the OP thinks to automatically run the macro from the Desktop, not have to open the workbook.
    Very good point, didn't even think about enabling macros

  8. #8
    Registered User
    Join Date
    10-24-2007
    Posts
    37

    Wink

    Thanks a lot Excelenator. You'r brilliant code worked perfect.
    Thanks for the intuitive ideas of davesexcel and royuk.

    I added the following code at the end of macro, so the file closed without saving it, so users can repeatedly use it.
    Please Login or Register  to view this content.
    Last edited by VBA Noob; 11-04-2007 at 11:26 AM.

  9. #9
    Registered User
    Join Date
    10-10-2012
    Location
    Ft Worth
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: how to launch excel macro from desktop

    Is it possible to hide the actual workbook in the background and only show the GUI for the Macro?

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,642

    Re: how to launch excel macro from desktop

    jimj,
    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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