Adding Opened Workbook to Collection

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi,

My code uses GetOpenFilename to open a file. Once opened, I check to see if the file is already opened.

My code works great if the file is not already opened. My question is, if the file is already opened, How do I include this file in my collection.

Here is my code:

FName = Application.GetOpenFilename(FileFilter:="Excel Files (*.xl*), *.xl*", Title:="Select DMS Source File To Be Opened")
If FName = False Then Exit Sub

TmpString = FName
If IsFileOpen(TmpString) Then
' File is Already Opened
Msg = vbCrLf & "Source File is Already Opened" & vbCrLf & vbCrLf
Msg = Msg & "Press OK to Continue with Opened Source File" & vbCrLf
Msg = Msg & "Press Cancel to Select Another Source File" & vbCrLf
Style = vbOKCancel '//Define buttons.
Title = "Source File Open" '// Define title.
'// Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbCancel Then Exit Sub
'
' How to link the Already Opened File to my Workbook Collection then Active Workbook
'
Else
' File Not Opened. Open File
Set SrcWkb = Workbooks.Open(FName)
TextBox1.Value = ActiveWorkbook.Name
TextBox2.Value = FileDateTime(FName)

End If

Any help would greatly be appreciated.

Thanks
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,827
Messages
6,121,818
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