Consulting

Results 1 to 4 of 4

Thread: File Selection- if user cancels- End Sub Then call macro1

  1. #1
    VBAX Regular
    Joined
    Feb 2011
    Posts
    34
    Location

    File Selection- if user cancels- End Sub Then call macro1

    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

  2. #2
    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

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,638
    Sub M_snb()
      with application.filedia log(3)
       if .show then 
         macro1
       else
         macro2
       end if
      end with
    end sub

  4. #4
    VBAX Regular
    Joined
    Feb 2011
    Posts
    34
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •