+ Reply to Thread
Results 1 to 5 of 5

running a macro when opening a work book

  1. #1
    Forum Contributor
    Join Date
    12-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    142

    running a macro when opening a work book

    I have the following code and it isn't working for me. The first part is on the specific sheet. The second code is in a module called "Shift" When I run the code manually it works, just not when I open the workbook. Any help?
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: running a macro when opening a work book

    The first part should be in the Workbook module, not a worksheet module.

    However, as far as I can see, you haven't selected a sheet or a range within a sheet so the effect could be fairly random.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    12-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    142

    Re: running a macro when opening a work book

    When I open this workbook I get the following error:
    Compile error:
    Expected variable or procedure, not module
    The error is in the following code:
    Please Login or Register  to view this content.
    I believe it's error is trying to call the "Shift" macro

  4. #4
    Forum Contributor
    Join Date
    12-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    142

    Re: running a macro when opening a work book

    So I think I figured it out. Here is the following code I inserted into "ThisWorkbook"
    The yellow code is what I had to add in order to make it work.
    Please Login or Register  to view this content.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: running a macro when opening a work book

    That would make sense ... as I said, there was no indication of sheet or range selection.

    Please note that a yellow font colour on a grey background is virtually unreadable.


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


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    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


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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