Code Concept Day – 1, Referencing a Workbook using VBA Using Workbook Names If you have the exact name of the workbook that you want to refer to, you can use the name in the code. Let’s begin with a simple example. If you have two workbooks open, and you want to activate the workbook with the name – Examples.xlsx, you can use the below code: Sub ActivateWorkbook() Workbooks("Examples.xlsx").Activate End Sub If you want to activate a workbook and select a specific cell in a worksheet in that workbook, you need to give the entire address of the cell (including the Workbook and the Worksheet name). Sub ActivateWorkbook() Workbooks("Examples.xlsx").Worksheets("Sheet1").Activate Range("A1").Select End Sub The above code first activates Sheet1 in the Examples.xlsx workbook and then selects cell A1 in the sheet. You will often see a code where a reference to a worksheet or a cell/range is made without referring to the wor...
Comments
Post a Comment