How to open 2 workbooks at the same time via VBA..

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
How can I open two workbooks at the same time with folder paths and names already given in cells C2 and C3.

C2 =
D:\Users\Tiger Woods\One Share\2021\03-2021 (user.one).xlsb
C3 =
D:\Users\Tiger Woods\Two Share\2021\03-2021 (user.two).xlsb

Thanks and will appreciate plenty.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You need a macro; for example:
VBA Code:
Sub OpenC2C3()
Workbooks.Open Range("C2").Value
Workbooks.Open Range("C3").Value
End Sub
Copy the code into a standard module of your vba, and when you are ready start the macro OpenC2C3

Bye
 
Upvote 0
You need a macro; for example:
VBA Code:
Sub OpenC2C3()
Workbooks.Open Range("C2").Value
Workbooks.Open Range("C3").Value
End Sub
Copy the code into a standard module of your vba, and when you are ready start the macro OpenC2C3

Bye
I get subscript out of range on C3. For C2 it works fine.
 
Upvote 0
I simplified it too much... Of course when you open C2 then Range C3 has a new value. Try this version:
VBA Code:
Sub OpenC2C3()
Dim FileOne As String, FileTwo As String
'
FileOne = Range("C2").Value
FileTwo = Range("C3").Value
'
Workbooks.Open FileOne
Workbooks.Open FileTwo
End Sub
Bye
 
Upvote 0
Solution
I simplified it too much... Of course when you open C2 then Range C3 has a new value. Try this version:
VBA Code:
Sub OpenC2C3()
Dim FileOne As String, FileTwo As String
'
FileOne = Range("C2").Value
FileTwo = Range("C3").Value
'
Workbooks.Open FileOne
Workbooks.Open FileTwo
End Sub
Bye
This works as expected. I was hoping if your code can be altered to now close both the workbooks, without saving any changes?
 
Upvote 0
If C2 and C3 in the starting workbook are unchanged then you could use the following macro:
VBA Code:
Sub CloseC2C3()
Dim FileOne As String, FileTwo As String, I As Long
'
For I = 0 To 1
    FileOne = ThisWorkbook.Sheets("TheSheetName").Range("C2").Offset(I, 0).Value         '<<<
    FileOne = Mid(FileOne, InStrRev(FileOne, "\", , vbTextCompare) + 1)
    Workbooks(FileOne).Close False
Next I
End Sub
Edit Sheet name in line marked <<<

Bye
 
Upvote 0
If C2 and C3 in the starting workbook are unchanged then you could use the following macro:
VBA Code:
Sub CloseC2C3()
Dim FileOne As String, FileTwo As String, I As Long
'
For I = 0 To 1
    FileOne = ThisWorkbook.Sheets("TheSheetName").Range("C2").Offset(I, 0).Value         '<<<
    FileOne = Mid(FileOne, InStrRev(FileOne, "\", , vbTextCompare) + 1)
    Workbooks(FileOne).Close False
Next I
End Sub
Edit Sheet name in line marked <<<

Bye

Many Thanks Anthony. God Bless.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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