Activate Workbook : Workbooks « Excel « VBA / Excel / Access / Word






Activate Workbook

 
     Sub ActivateWorkbook1()
         Dim sFullName As String
         Dim sFileName As String
         Dim myWorkbook As Workbook

         sFullName = "C:\Data\SalesData1.xlsx"
         sFileName = sGetFileName(sFullName)
         If bIsWorkbookOpen(sFileName) Then
         Set myWorkbook = Workbooks(sFileName)
         myWorkbook.Activate
         Else
         Set myWorkbook = Workbooks.Open(FileName:=sFullName)
         End If
     End Sub

 








Related examples in the same category

1.To select a Workbook object from the Workbooks Collection object
2.To avoid confusion, you can select a workbook unambiguously- if you know the name of the desired Workbook object
3.When you need to step through several objects in a collection, use a loop and a looping variable to represent the index of the object to be returned.
4.Work your way through the entire object hierarchy to set one property
5.Creating a New Blank Workbook
6.Stores the current SheetsInNewWorkbook property, sets the SheetsInNewWorkbook property to 12, creates a new workbook (with those 12 worksheets), and then restores the SheetsInNewWorkbook setting to its previous value
7.Values for the UpdateLinks Argument
8.Opens the workbook named Plan.xls stored in the D:\Planning folder, providing the password for opening the workbook
9.Opens the text file named Data13.txt in the folder z:\transfer using an exclamation point (!) as the delimiter character
10.Closing All Open Workbooks
11.Sharing a Workbook
12.Declare a Workbook object variable and assign the ActiveWorkbook object to it, so that subsequent code can work with the object variable:
13.Working with Worksheets to add a worksheet
14.Copying or Moving a Worksheet
15.Moves the worksheet named Homes from the workbook named Planning.xls to the workbook named Building Schedule.xls, inserting the worksheet before the first existing worksheet in the workbook
16.Prints the first two pages of the worksheet named Summary in the workbook named Planning.xls to a file named Planning Summary.prn in the network folder \\server\to_print:
17.Returns the text in the active cell in the first window open on the workbook named Planning.xls:
18.Creating a Named Range from Workbooks
19.Deleting a Named Range
20.To apply a read-only recommendation to a workbook, set its ReadOnlyRecommended property to True
21.Activating a Window
22.Arranging and Resizing Windows
23.Use For...Next loop through Workbooks
24.Add Workbooks and save it as a new file
25.Use the return value of the Add method to create an object variable that refers to the new workbook
26.The Add method allows you to specify a template for the new workbook.
27.To add an existing workbook file to the Workbooks collection, you use the Open method
28.Getting a Filename from a Path
29.To see if the workbook is already a member of the Workbooks collection
30.Files in the Same Directory
31.Overwriting an Existing Workbook