+ Reply to Thread
Results 1 to 10 of 10

Copy master workbook and catch error from copied one

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Copy master workbook and catch error from copied one

    Hi Guys,

    i have master workbook with code like here:

    In module:

    Please Login or Register  to view this content.
    and in ThisWorkbook event:

    Please Login or Register  to view this content.
    Now macro is copying master workbook, doing calculations there (whatever!) and what i want to catch is error while copy workbook is closed.
    So if error (in example i am reising it especially) pass copy master name to main sub into: "CopyWorkbookError" procedure.

    How can i do this?

    Best,
    Jacek
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Copy master workbook and catch error from copied one

    I'm not sure what you want to do - you can pass values between modules by declaring a variable at the top or your module as Global, like

    Global strWBName As String

    When you assign a value to strWBName, that value will be available to all procedures (to read or to change).

    You could also make your workbook into a template and then when it is opened, the user will be forced to save it with a different name.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Copy master workbook and catch error from copied one

    Thank you Bernie!

    Please Login or Register  to view this content.
    i know but what about passing errors from one master workbook to its copy?

    You could also make your workbook into a template and then when it is opened, the user will be forced to save it with a different name.
    this is not want i want.

    Generally every master copy has closing trigger --> i am refreshing tables there.
    I have also code from master which is copying master workbook and doing some code and when they are closed --> trigger is also fired to refresh table.

    And my core issue here is that sometimes in copy i can get error while refreshint tables - i have to log this somehow.
    For examply i have 5 different copies and running code from master.
    In copy number 4 i am getting error, how to pass it to master code? How to raise it in master, not a copy?
    It is possible?

    Jacek

  4. #4
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Copy master workbook and catch error from copied one

    Hi Guys,

    anyone?

    Jacek

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Copy master workbook and catch error from copied one

    If you are running the code from the master workbook, you should not have any code in the copies - save the copies as .xlsx files, then pass their workbook object as a parameter to your code in the master. Then any error raised will be in the master.

  6. #6
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Copy master workbook and catch error from copied one

    Hi Bernie,

    i am not entirely understand:

    If you are running the code from the master workbook, you should not have any code in the copies
    If you are creating copy from xlsm to xlsm it will have VBA code inside after copying. You mean to not copy as xlsm only as xlsx?

    then pass their workbook object as a parameter to your code in the master.
    you mean workbooks open method?

    Ok but i will return to my source question.
    It is possible to :
    do a copy for master, run code on this opened copy and if error raised --> pass variable into master ?

    Jacek

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Copy master workbook and catch error from copied one

    When you make the copy, use code like this to create an object that you can address in your code - when you want to process the copy, use the wbCopy object - then, any error raised in your will be raised in the workbook with the code

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Copy master workbook and catch error from copied one

    thank you,

    it is good idea.

    And this is only one way to do this and pass error from copied version?

    Jacek

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Copy master workbook and catch error from copied one

    No - but all the methods require some inter-workbook communication. If you can't think of a dozen more ways to do any task in Excel then you're not really trying But the way that I outlined would be my preferred method.

  10. #10
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Copy master workbook and catch error from copied one

    thank you Bernie.

    Best,
    Jacek

+ 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. Copy the Data from Multiple workbook to Master Workbook as Conslidated
    By venugosr in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-19-2017, 01:32 AM
  2. [SOLVED] excel master file macro not carrying to new workbook when copied
    By Jack7774 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-02-2016, 10:34 AM
  3. Replies: 12
    Last Post: 07-29-2014, 01:06 PM
  4. Copy paste last row from each workbook in master workbook on header criteria
    By farrukh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-30-2013, 07:28 AM
  5. Replies: 2
    Last Post: 09-11-2012, 09:42 AM
  6. Replies: 3
    Last Post: 05-17-2012, 11:25 AM
  7. [SOLVED] VBA to copy row in a workbook and auto fill in Master workbook.
    By adriel19pr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-29-2012, 03:51 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