PDA

View Full Version : Sleeper: Cancelling a browse box.



Dowsey1977
09-19-2005, 04:59 AM
Hi,

I'm using the below code to open a browse box, then the user clicks on a spreadsheet and the 'Form 6' sheet is copied from the imported spreadsheet into the main spreadsheet. However, if the user changes their mind and clicks cancel on the browse box, at the moment it brings up an error message, but I want it to just end the macro and do nothing. How do I get it to do this??

I tried using:


Select Case sWBToOpen

in various places and although I managed to get it to work with Case vbCancel, it then brought up error messages in different places.



Sub Test()
'Macro Purpose: To test the GetOpenFilenameFrom function
Dim sWBToOpen As Variant
Dim Answer
sWBToOpen = GetOpenFilenameFrom(Range("A3").Value)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
If Not sWBToOpen = False Then Workbooks.Open (sWBToOpen)
Sheets("FORM 6").Select
Sheets("FORM 6").Copy Before:=Workbooks("NEW FORM 6.xls").Sheets(2)
Sheets("FORM 6").Select
Range("A72").Select
Answer = MsgBox("The Form 6 sheet has successfully been imported and the data is ready to copy." & vbCrLf & vbCrLf & _
"Click 'Ok' to copy the data and 'Cancel' to view Form 6 before copying", vbOKCancel, "Payment Information")
If Answer = vbOK Then
Call WhichTransaction
Sheets("Form 6").Select
ActiveSheet.Delete
Sheets("Control Sheet").Select
Else
Sheets("FORM 6").Select
End If
Windows("Combined Form 6 Template macro2.xls").Activate
ActiveWindow.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub




Any help would be appreciated.

jimboy
09-19-2005, 05:42 AM
Try this;


Sub test()
Dim a
a = Application.GetOpenFilename
If a = False Then
MsgBox "False"
Else
MsgBox "True"
End If
End Sub