Vba macro to open workbook and then activate the workbook from which the macro wss started

Vbanoob98

Board Regular
Joined
Sep 13, 2019
Messages
128
I have 1 macro that I use on different workbooks to pass data into a fixed workbook.

So I want to be able to open that fixed workbook and then run my copying macro from the changing workbooks. The problem is when I use vba to open the workbook it makes it the active one and the macro copies the data from the fixed workbook.

Any help would be really appreciated. :)
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Found the solution. Call this first then my other macro

Code:
Sub OPEN1()
 Dim wb As Workbook, currentWb As Workbook
    Set currentWb = ThisWorkbook
    Set wb = Workbooks.Open("file")
    ' if you want to close opened workbook
    'wb.Close
    ' if you want to bring to front original workbook
    currentWb.Activate

End Sub​
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,932
Members
452,539
Latest member
delvey

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