Hi all -
I'm close to getting this working - just not quite there.
When I choose "no" shouuld set the value of myTest to False and pass
back to the main routine
Main routine checks for myTest = False and exits sub if true
However, does not exit.
Continues to execute through input boxes.
Where did I go wrong?
Thanks
-marc
Code
Sub pt_ImportData()
'j-walk
Dim PathMsg As String, FileMsg As String, SheetMsg As String
Dim inboxTitle As String
Dim default As String
Dim p As String, f As String, s As String
Dim myTest As Boolean
PathMsg = "Enter the path :"
FileMsg = "Enter the file name :"
SheetMsg = "Enter the sheet name :"
inboxTitle = "Import Data"
default = ""
myTest = True
'Verify Delete of current data
pt_ClearDataDecision (myTest)
If myTest = False Then
Exit Sub
Else
p = InputBox(PathMsg, inboxTitle, default)
f = InputBox(FileMsg, inboxTitle, default)
s = InputBox(SheetMsg, inboxTitle, default)
End If
On Error GoTo errhandler
Application.ScreenUpdating = False
For r = 1 To 3000
For C = 1 To 7
a = Cells(r, C).Address
Cells(r, C) = GetValue(p, f, s, a)
Next C
Next r
Application.ScreenUpdating = True
errhandler:
End Sub
Private Function GetValue(path, file, sheet, ref)
'jwalk
' Retrieves a value from a closed workbook
Dim arg As String
' Make sure the file exists
If Right(path, 1) <> "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
' Create the argument
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Range("A1").Address(, , xlR1C1)
' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function
Sub pt_ClearDataDecision(myTest As Boolean)
Dim Res As Long
Res = MsgBox("Caution-You are about to clear Data!" & vbCrLf & _
"Are you sure you want to do this?" _
, vbYesNo + vbExclamation, "Data Warning")
Select Case Res
Case vbYes
pt_ClearData
Case vbNo
myTest = False
Exit Sub
Case Else
myTest = False
Exit Sub
End Select
End Sub
Private Sub pt_ClearData()
Set wbBook = ThisWorkbook
With wbBook
Set wsData = .Worksheets("Data")
End With
With wsData
.UsedRange.Clear
End With
End Sub
Display More