Thursday 24 October 2019

Excel macro to save workbook on another session of excel


Im trying to make a macro in one session of excel that saves a particular workbook in another session of excel.


Lets say i have Workbook1 and Workbook2 and i have opened them in different excel sessions.What i want is to make macro that saves Workbook2 from Workbook1.



Answer



Although a macro is stored in a specific workbook, every macro (or SUB) is aware of (and has access to) all workbooks that are open in Excel. Access to other workbooks is most easily obtained by using the Workbooks collection (Application.Workbooks) or by referencing a particular workbook by index (Application.Workbooks(1) or by name Application.Workbooks("SomeWorkbook.xlsx"). To save a file, you can use the .Save method of a workbook class.


To answer your question:


Sub SaveSomeWorkbook()
Application.Workbooks("Workbook2.xlsx").Save
End Sub

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...