sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,404
- Office Version
- 2016
- Platform
- Windows
I'm using this to select an existing Excel file and then go on afterwards to copy data to it.
As you can see, the user is prompted to find their current file and then it is opened, but how can I adjust it so that if it is already open the rest of the code runs without 'reopening' the file and giving the user the message asking if they want to reopen it?
As you can see, the user is prompted to find their current file and then it is opened, but how can I adjust it so that if it is already open the rest of the code runs without 'reopening' the file and giving the user the message asking if they want to reopen it?
Code:
Call MsgBox("Select your existing Toolbox to import data", vbExclamation Or vbDefaultButton1, "Select existing file")
FileToOpen = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsm), *.xlsm")
If FileToOpen = "False" Then
ActiveWorkbook.Close SaveChanges:=False
End If
filePath = Left$(FileToOpen, InStrRev(FileToOpen, "\"))
filename = Mid$(FileToOpen, InStrRev(FileToOpen, "\") + 1)
Application.ScreenUpdating = False
Application.EnableEvents = False