Macro to open workbook and set as current active workbook

Tom Allen

Board Regular
Joined
Sep 26, 2014
Messages
92
Hi I am using the following code to open another workbook and it works great. However I was wondering how it could be adapted so that when it opens the workbook it also makes the newly open workbook the current active workbook on screen.

At the moment it opens but I remain on my current workbook.

Code:
Sub Finance_Overview()
Application.ScreenUpdating = False
Workbooks.Open Filename:="D:\Finance\Finance Overview.xlsm"
ThisWorkbook.Activate
Application.ScreenUpdating = True
End Sub

I would be grateful for any help.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi I am using the following code to open another workbook and it works great. However I was wondering how it could be adapted so that when it opens the workbook it also makes the newly open workbook the current active workbook on screen.

At the moment it opens but I remain on my current workbook.

Code:
Sub Finance_Overview()
Application.ScreenUpdating = False
Workbooks.Open Filename:="D:\Finance\Finance Overview.xlsm"
ThisWorkbook.Activate
Application.ScreenUpdating = True
End Sub

I would be grateful for any help.




Sub abc()


Dim wb As Workbook, wb1 As Workbook
Dim xpath As String


Set wb = ThisWorkbook




xpath = "C:\Users\lakshya\Desktop\excel & vba training\copy.xlsx"


Set wb1 = Workbooks.Open(xpath)
wb1.Activate
' now u can write the code
wb1.Close (False)
wb.Activate


End Sub
 
Upvote 0
Thanks for the reply. I'm quite a novice at this so I don't suppose you could elaborate a bit more could you. I'm guessing I need to enter something into where you have put "now u can write the code" but I'm not sure what.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top