matchlessman
New Member
Hi Everyone,
First post here from a beginner in VBA!
I'm creating a macro so that a user can choose a file to open in order to transfer its data into the active workbook.
If the chosen file is already opened, the warning message "Do you want to reopen ..." appears, and if the user selects "No", a Microsoft VB error message appears. In the event where the user selects "No", I want the macro to simply stop (close File Explorer without any error message appearing).
I've already searched the web and I've seen that Functions are generally used to solve this problem. However I have not been able to adapt a Function for my macro. Could someone help me out?
Kind regards,
Maxwell
First post here from a beginner in VBA!
I'm creating a macro so that a user can choose a file to open in order to transfer its data into the active workbook.
If the chosen file is already opened, the warning message "Do you want to reopen ..." appears, and if the user selects "No", a Microsoft VB error message appears. In the event where the user selects "No", I want the macro to simply stop (close File Explorer without any error message appearing).
I've already searched the web and I've seen that Functions are generally used to solve this problem. However I have not been able to adapt a Function for my macro. Could someone help me out?
Code:
Dim wbContr As Workbook
Dim wbVerif As Workbook
Dim nmVerif As Variant
Sub ChooseFile()
Set wbContr = ActiveWorkbook
'Open File Explorer to choose the workbook
nmVerif = Application.GetOpenFilename
'Exit File Explorer if user selects "Cancel" instead of "Open"
If nmVerif = False Then End
Set wbVerif = Workbooks.Open(nmVerif)
End Sub
Kind regards,
Maxwell
Last edited by a moderator: