+ Reply to Thread
Results 1 to 14 of 14

Vba Macro to save File2 if File1 saved

  1. #1
    Registered User
    Join Date
    12-20-2013
    Location
    Usa, Washington
    MS-Off Ver
    2003
    Posts
    9

    Exclamation Vba Macro to save File2 if File1 saved

    Good day,

    This is my first post since I joined the forum. Hopefully not the last.

    I have two excel file:
    C:\Book1.xls
    C:\Book2.xls


    I am looking vba to do the following:

    Whenever I do Save for Book1, I want Book2 to auto save without prompt.

    Thank you for your help in advance.

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Post Re: Vba Macro to save File2 if File1 saved

    Hi abbasabdulla,
    Welcome to the forum. We certainly hope that you will share many more posts with us here.

    As to your query, please try the following code (should be saved within Workbook_AfterSave event of Book1):
    Please Login or Register  to view this content.
    Let us know if anything. Regards.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Vba Macro to save File2 if File1 saved

    Hi, jewelsharma,

    OP has given Excel2003 as Application - does XL10 support Workbook_AfterSave? Iīm not so sure but wasnīt that event introduced with Excel2007 or later?

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Vba Macro to save File2 if File1 saved

    Hi Guru Holger,
    Oops! my bad. I should not be ignorant to the Excel version of the OP.

    Would you know a way to help the OP here.
    Regards.

    EDIT: Does the Excel 2003 version have a "Before_Save" Event? If so, we can modify it to save File 2.
    Last edited by jewelsharma; 04-23-2014 at 01:02 AM. Reason: idea

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Vba Macro to save File2 if File1 saved

    Hi, jewelsharma,

    letīs wait for the OP to confirm which version of Excel is used. And sorry from my side as well, I was wrong with the internal number: XL10 is Excel2002/XP while Excel2003 is XL11.

    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    12-20-2013
    Location
    Usa, Washington
    MS-Off Ver
    2003
    Posts
    9

    Re: Vba Macro to save File2 if File1 saved

    Dear jewelsharma,

    I am using excel 2003, the code doesn't do any action and there is no error message.
    I prefer if the code can be placed in a separate file other than book 1or 2.

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Post Re: Vba Macro to save File2 if File1 saved

    Hi abbasabdulla,
    To answer your queries,
    I am using excel 2003, the code doesn't do any action and there is no error message.
    Unfortunately, Excel 2003 does not have the "After Save" event; and hence the code does nothing.
    I prefer if the code can be placed in a separate file other than book 1or 2.
    I understand that you desire to save Book2 everytime you save Book1; then the code needs to rest in Book1, and be executed when you "Save" it. I can't think of another way. Now, I beleive Excel 2003 has a "Before Save" event, so try this code (which, for the above mentioned reasons, should be within Workbook_BeforeSave event of Book1):
    Please Login or Register  to view this content.
    This code should execute every time you are about to save Book1 and ask you if you would like to save Book2 as well.
    Let us know if anything.

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Vba Macro to save File2 if File1 saved

    Hi, abbasabdulla,

    if both workbooks are open by the time and you want the coide in any other workbook I think you would need to use Class Programming which could be placed in the personal macro workbook.

    Please Login or Register  to view this content.
    Ciao,
    Holger

  9. #9
    Registered User
    Join Date
    12-20-2013
    Location
    Usa, Washington
    MS-Off Ver
    2003
    Posts
    9

    Re: Vba Macro to save File2 if File1 saved

    Hi jewelsharma /HaHoBe,

    I really appreciate your help and I am very thankful to you. Right now I have no access to pc so once I test the vba code I will let you know my feedback accordingly.

    Best regards,
    Abbasabdulla

  10. #10
    Registered User
    Join Date
    12-20-2013
    Location
    Usa, Washington
    MS-Off Ver
    2003
    Posts
    9

    Re: Vba Macro to save File2 if File1 saved

    Hi HaHoBe/ jewelsharma,

    It seems that this codes does no action in excel 2003. Whenever i paste the code to vba module or class model, it will disappear as soon I exit from VBA editor. Please give me your feedback if there is something can be done.

  11. #11
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Vba Macro to save File2 if File1 saved

    Hi, abbasabdulla,

    you would need to paste the code into ThisWorkbook as only when placed there the event will be raised, in your case it should be Book1 and ThisWorkbook.

    Whenever i paste the code to vba module or class model, it will disappear as soon I exit from VBA editor.
    Sorry I donīt understand what you mean by this. Code canīt be seen but doesnīt need to as an event will be raised and the code will start automaticly. Adn the code will be saved with the workbook where itīs pasted/written into so that workbook needs to be saved after any change in the VBE.

    Ciao,
    Holger

  12. #12
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Vba Macro to save File2 if File1 saved

    Hi abbasabdulla,
    As Guru Holger pointed out, the code needs to be in "ThisWorkbook" object of your "Book1" file. If you are not familiar with "how to do this", please let us know.
    (and remember to save the workbook after pasting the code).
    Cheers!

  13. #13
    Registered User
    Join Date
    12-20-2013
    Location
    Usa, Washington
    MS-Off Ver
    2003
    Posts
    9

    Re: Vba Macro to save File2 if File1 saved

    Hi jewelsharma,
    I am beginner vba, I am not familiar with that.

  14. #14
    Registered User
    Join Date
    12-20-2013
    Location
    Usa, Washington
    MS-Off Ver
    2003
    Posts
    9

    Re: Vba Macro to save File2 if File1 saved

    Hi jewelsharma /HaHoBe,

    Both codes works perfect. Thank you for your help.

+ 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 data from file1.xls to file2.xls and convert do html file
    By alban01 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-13-2013, 10:39 AM
  2. Multi process macro - save open WB, copy data to new WB, del saved...
    By Alexm963 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-31-2012, 01:42 AM
  3. Loop through File1 with File2 and show differences in third file
    By sravanthi009 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2011, 09:03 AM
  4. Copy Data From File1 to File2
    By simonstaton in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-04-2011, 06:19 AM
  5. [SOLVED] 'document not saved' for 'save' or 'save as' an EXCEL file
    By Judy Chuang in forum Excel General
    Replies: 1
    Last Post: 07-11-2005, 06:05 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