PDA

View Full Version : File Selection- if user cancels- End Sub Then call macro1



Foncesa
09-09-2022, 10:44 AM
Hi,

If user selects cancel (condition False) then End Sub and call macro1 and if user selects file (condition True) then call macro2
This codes are for file selection.
Thanks in advance.



Sub LoadLV()
Dim wb As Workbook
Dim pickfile As Variant
pickfile = Application.GetOpenFilename(fileFilter:="Excel Files (*.*), *.csv", _
Title:="Choose File:::::::::", MultiSelect:=False)
If pickfile = False Then Exit Sub
Set wb = Workbooks.Open(pickfile, True, False)
End Sub

arnelgp
09-10-2022, 04:43 AM
Sub LoadLV()
Dim wb As Workbook
Dim pickfile As String
pickfile = Application.GetOpenFilename(fileFilter:="Excel Files (*.*), *.csv", _
Title:="Choose File:::::::::", MultiSelect:=False)

If pickflie = "False" Then
Call macro1
Else
Call macro2
End If

snb
09-11-2022, 03:39 AM
Sub M_snb()
with application.filedia log(3)
if .show then
macro1
else
macro2
end if
end with
end sub

Foncesa
09-13-2022, 06:30 PM
Hi snb,


Sub LoadLV()
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant
Dim Searchtext As String
With fd
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
Set vrtSelectedItem = Workbooks.Open(vrtSelectedItem, True, False)
Next vrtSelectedItem
Macro1
Else
Macro2
End If
End With
Set fd = Nothing
End Sub


Thanks SNB, i did this way. one thing before importing data from file i want to check text string in Column D2 for "Agreement Particulars" if it is there, then goto Macro1, else flash message improper file, then call Macro2.