Hi
I've got a Sub which allows a user to import data from a file, but I need the Sub to stop running if a user doesn't select a file, when a folder is opened.
Does anyone remember how to do this?
I'd be grateful if you could advise where to insert the amendment in the code below, please?
TIA
I've got a Sub which allows a user to import data from a file, but I need the Sub to stop running if a user doesn't select a file, when a folder is opened.
Does anyone remember how to do this?
I'd be grateful if you could advise where to insert the amendment in the code below, please?
TIA
VBA Code:
Sub Import1()
Dim fd As FileDialog
Dim filewaschosen As Boolean
Dim Report As Workbook
Dim iWB As Workbook
Set Report = ActiveWorkbook
Set fd = Application.FileDialog(msoFileDialogOpen)
fd.Filters.Clear
'fd.Filters.Add "xlsx files", "*.xlsx"
fd.Filters.Add "Custom Excel Files", "*.xlsx, *.xlsm, *.xls"
fd.AllowMultiSelect = False
fd.InitialFileName = Environ("UserProfile") & "\Box\Proposals & Contracts"
filewaschosen = fd.Show
fd.Execute
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A2:G" & lastrow).Copy
Report.Activate
ACV.Visible = True
ACV.Activate
Range("A2:G" & lastrow).PasteSpecial
End Sub