+ Reply to Thread
Results 1 to 4 of 4

Excel macro doesn't run after saving and reopening the file

  1. #1
    Registered User
    Join Date
    02-11-2011
    Location
    Vilnius, Lithuania
    MS-Off Ver
    Excel 2016
    Posts
    83

    Excel macro doesn't run after saving and reopening the file

    Hello, I have inserted simple macro code into Module1 in excel workbook:

    Please Login or Register  to view this content.
    It worked perfectly, but then I saved workbook (as xlsm). Once I have reopened a workbook - hitting F4 key is doing nothing.
    And code is still there in the module1. It should insert current dateTime to the active cell.
    Macros are enabled.

    This is my first macro ever, maybe I did something wrong?
    Last edited by JackBauer; 06-17-2020 at 11:33 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,289

    Re: Excel macro doesn't run after saving and reopening the file

    Did you run the ShortcutDateAndTime routine after reopening the workbook to set the OnKey assignment again?
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: Excel macro doesn't run after saving and reopening the file

    Please Login or Register  to view this content.
    This code should be in ThisWorkbook module, in Workbook_Open() event. This will ensure that you don't have to manually run ShortcutDateAndTime() sub.
    EDIT: This binds F4 to "DateAndTime" sub.
    Please Login or Register  to view this content.
    Now, you may want to reset/disable Application.OnKey before you close the workbook...
    To unassign it... you'd use Application.OnKey "{F4}" without the argument for sub to run on key.
    Ex:
    Please Login or Register  to view this content.
    Personally, I'd just use Macro options to assign key combo. Rather than use Application.OnKey.
    Last edited by CK76; 06-17-2020 at 12:19 PM. Reason: Grammar
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  4. #4
    Registered User
    Join Date
    02-11-2011
    Location
    Vilnius, Lithuania
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Excel macro doesn't run after saving and reopening the file

    Wow, thank you, will try.

    Well this will be used to log work events and elderly people who are not savvy with computers in general, will use that, so I must avoid any key combinations.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Shapes move in excel upon saving and reopening
    By Weathertuck in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-17-2021, 09:51 PM
  2. VBA ~20x slower after saving; closing; reopening file
    By easperhe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-24-2018, 11:40 PM
  3. Macro doesn't initiate when reopening workbook
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-27-2015, 01:16 PM
  4. [SOLVED] Timer macro reopening the file
    By sakmsb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2014, 02:40 AM
  5. Replies: 1
    Last Post: 03-01-2013, 06:59 PM
  6. [SOLVED] Macro for border not working after reopening the file
    By var in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2012, 04:30 PM
  7. Excel File Reformats when Reopening
    By VG3 in forum Excel General
    Replies: 1
    Last Post: 06-05-2009, 10:31 AM

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