+ Reply to Thread
Results 1 to 2 of 2

Determine which macro and line executed last in a VBA macro.

  1. #1
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,167

    Determine which macro and line executed last in a VBA macro.

    I'm not sure if this is possible, and most likely beyond my capabilities.
    I have an Excel template with many Subs and Functions which I am finding it difficult to follow what is happening, or in the order of what is happening.

    I want to add a simple SaveAs bit of code for an Excel file that is automated via a CMM (Coordinate Measuring Machine) software.
    This software reads from three different txt files and places data on a worksheet (Which it names "Report") and somewhere, either in the beginning or near the end of the macro(s) a workbook name is created.
    The way these macros are written and broken into so many routines is difficult to follow or figure out flow.
    The workbook name is generated from one or more of the three txt files used.

    In our process of running parts on the CMM, these excel workbooks are generated automatically.

    My best guess, is, if I can determine which macro and or line of the macro that runs last, I may be able to insert the "SaveAs" code to automatically save the workbook.
    its manually saved now, and far too many times when in a rush, it isn't saved.

    Is there a way with VBA to determine the last Sub/Function and or line of code executed?

    The zip file attached has a .xlt and a .xls file.
    Attached Files Attached Files
    Regards

    Rick
    Win10, Office 365

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Determine which macro and line executed last in a VBA macro.

    Well if the program terminates in an error then the VB Editor should show it.

    Here is a bit of code that I use to "instrument" my code. Download the module and include it in your code. The subroutine takes three arguments:
    - The message you want to display
    - The pathname to the log file (Optional - default is the same directory with the spreadsheet)
    - The name of the log file (Optional - default is the spreadsheet name with .txt instead of .xls?.

    Call the subroutine like this
    Please Login or Register  to view this content.
    Wherever you want to track execution.

    The log file has a date stamp and the indicated message for each time it is called. If you want to turn it off, set the LogFlag to False.
    Attached Files Attached Files
    Last edited by dflak; 06-07-2023 at 10:26 AM.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ 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. Macro to paste formula in colK after a macro executed
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-20-2017, 08:39 PM
  2. Macro executed within one tab
    By toplisek in forum Excel General
    Replies: 2
    Last Post: 07-03-2015, 04:49 AM
  3. 400 - error when macro executed
    By dantray02 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-10-2014, 09:10 AM
  4. Need macro help restricting when it is executed
    By graduate106 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 05-08-2013, 11:00 AM
  5. [SOLVED] Create Yes/No message box to determine if a macro should be executed
    By poptart141 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-22-2013, 02:18 PM
  6. Replies: 7
    Last Post: 04-19-2006, 03:10 PM

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