P
Paige
Have sub below that is used to get data from closed workbook (i.e., the
source file); it actually opens the file in read-only then closes again; it
works great. However, I can’t seem to integrate into it code to check to see
if the file which the user selects in the file dialog is already open or not.
Have tried functions, etc., but I think my problem could be that it is
opening the selected file prior to checking if it is open….just a guess
anyway. Is it possible to have Excel check to see if the file selected by
the user is open already, and if it is, then somehow allow the user to select
the source file in the Excel window, at which time Excel will pull in the
data that way? If it is not open, it would proceed as normal with the code
below. If not, then how can I modify it to just check if the file is open?
Dim WB As Workbook
Set WB = Workbooks.Open(Application.GetOpenFilename(FileFilter:="All
Files(*.*),*.xls,All Files (*.*),*.*"), True, True)
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Input and P&L")
.Range("E9").Value = WB.Worksheets("Input and P&L").Range("e9").Value
.Range("E10").Value = WB.Worksheets("Input and
P&L").Range("e10").Value
End With
WB.Close False
Set WB = Nothing
Application.ScreenUpdating = True
End Sub
source file); it actually opens the file in read-only then closes again; it
works great. However, I can’t seem to integrate into it code to check to see
if the file which the user selects in the file dialog is already open or not.
Have tried functions, etc., but I think my problem could be that it is
opening the selected file prior to checking if it is open….just a guess
anyway. Is it possible to have Excel check to see if the file selected by
the user is open already, and if it is, then somehow allow the user to select
the source file in the Excel window, at which time Excel will pull in the
data that way? If it is not open, it would proceed as normal with the code
below. If not, then how can I modify it to just check if the file is open?
Dim WB As Workbook
Set WB = Workbooks.Open(Application.GetOpenFilename(FileFilter:="All
Files(*.*),*.xls,All Files (*.*),*.*"), True, True)
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Input and P&L")
.Range("E9").Value = WB.Worksheets("Input and P&L").Range("e9").Value
.Range("E10").Value = WB.Worksheets("Input and
P&L").Range("e10").Value
End With
WB.Close False
Set WB = Nothing
Application.ScreenUpdating = True
End Sub