+ Reply to Thread
Results 1 to 4 of 4

Command button macro

  1. #1
    Registered User
    Join Date
    07-11-2011
    Location
    Oxford, Mississippi
    MS-Off Ver
    Excel 2003
    Posts
    2

    Command button macro

    I'm having trouble making this macro I wrote run with a command button.
    The macro is a demo macro I'm writing for a much larger project, and this is basically what it does:
    It allows the user to browse for a pre-formatted file. It then reads the file, stores a few values and plugs it into the designated cells in the workbook the macro is running out of.

    The macro itself works when I manually run the macro. However, when I run the macro through the command button, it will execute the first half but not the last half. More specifically, it searches for the file, opens it and makes it the active window, but does not plug in the values in the designated cells.
    Please Login or Register  to view this content.
    Am I not using the correct format for the command button? or is it something else?

    Thanks,
    Last edited by Paul; 07-11-2011 at 04:12 PM. Reason: Added code tags for new user. Please do so yourself in the future.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Command button macro

    Your macro can be shortened to:

    Please Login or Register  to view this content.
    No need to store the locations of the values in the other workbook that you are looking for. A couple things I'd ask you:

    Are there multiple worksheets in the workbook that is selected? Your code does not deal with sheets, so the active sheet will be where data is taken from.

    I hate to ask, but are you sure you are looking for the data in cells A1, B1, C1, and B2?
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    07-11-2011
    Location
    Oxford, Mississippi
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Command button macro

    ahh yes, that shortens it a lot...
    and yes, I was also experimenting with multiple worksheets to prep for the actual project.

    Also I've managed to fix it by simply doing:

    call MacroName

    and now it works... don't know why I didn't think of that before...

    Thanks for the speedy reply!

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Command button macro

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

    Here's an alternative
    Please Login or Register  to view this content.
    Last edited by royUK; 07-12-2011 at 02:30 AM.
    Hope that helps.

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

    Free DataBaseForm example

+ 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