Do-While Loop Error w/ Condition Declaration @ End of Loop

idlewyld89

New Member
Joined
Jun 10, 2018
Messages
23
Hi everyone, most likely a simple explanation here but I'm not seeing it...

I get a "Compile Error - Loop without Do" message on the first line of the code below. I've got a do in there... obviously it's placed in such a way that it doesn't recognize it, but I'm not comfortable with what needs to be changed in order to get it working.

Ultimately, the routine asks the user to select an external file. Additionally, the user is asked to confirm their selection, and the loop is meant to recycle the same routine in the case that the user selects "No" at the confirmation dialog.

Code:
Private Sub ImportData()' References: TestWSName,
' Dependents: NoREV_tool,


' ~~> Prompts user to select the source file to be used for reporting, opens the file, and copies it's contents.
' ~~> Error Handling: File Selection (on Cancel, END Sub) - File Confirmation (on No, RESET FileDialog / on Cancel, END Sub)


Dim fd As FileDialog
Dim DataWbk As Workbook
Dim DataPath As String
Dim ReportWbk As Workbook
Dim MsgResponse As Integer
Dim FileSelection As Integer


Set ReportWbk = ActiveWorkbook


If TestWSName(MainSheet) = True Then


    Sheets(MainSheet).Delete
    
End If


Set fd = Application.FileDialog(msoFileDialogFilePicker)
    fd.Title = "Import File"
    fd.InitialView = msoFileDialogViewSmallIcons
    fd.Filters.Clear
    fd.Filters.Add "Excel files", "*.xlsx;*.xls;*.xlsm"
    fd.ButtonName = "Open VAW File"


Do


    FileSelection = fd.Show
    
    If FileSelection <> -1 Then


        MsgBox "No File Selected" & vbNewLine & vbNewLine & "Please Download Your File From:" & vbNewLine & vbNewLine & "Intranet > VAW > Operations > Fleet Status", vbOKOnly, "Warning"
        End
    
    Else
    
        DataPath = Right$(fd.SelectedItems.Item(1), Len(fd.SelectedItems.Item(1)) - InStrRev(fd.SelectedItems.Item(1), "\"))
    
        MsgResponse = MsgBox("Please confirm your selected file:" & vbNewLine & vbNewLine & DataPath, vbYesNoCancel, "File Confirmation")
        
        If MsgResponse = vbYes Then
        
            DataPath = Application.FileDialog(msoFileDialogFilePicker).SelectedItems.Item(1)
    
            Set DataWbk = Workbooks.Open(DataPath)
            MainSheet = DataWbk.Sheets(1)
            DataWbk.Sheets(1).Copy Before:=ReportWbk.Sheets(1)
            DataWbk.Close False
            ReportWbk.Sheets(MainSheet).Activate
            
        ElseIf MsgResponse = vbCancel Then
        
            MsgBox "No File Selected" & vbNewLine & vbNewLine & "Please Download Your File From:" & vbNewLine & vbNewLine & "Intranet > VAW > Operations > Fleet Status", vbOKOnly, "Warning"
            End
        
        End If
    
Loop While MsgResponse = vbNo
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You didn't post all your code, but it may be you're missing an End If. The compiler often errs when citing Loop w/o Do and If w/o End If ....
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top