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
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