dimanche 19 avril 2015

Add an If/Else condition at end of my Refresh Data Macro

I have a macro which is generated from a button on sheet 1 of my workbook. When the macro is run it removes password protection from my workbook, refreshes data link with another workbook (the macro takes the user to the directory path but the user has to highlight the workbook and then select OK), the macro then completes by placing password protection back on my workbook.


This works well as long as the user highlights the workbook and selects OK. If the user should decide to select Cancel the macro will not complete.


Is there an If/Else condition that I could write into the macro to avoid the debug window if the user selects Cancel instead of highlight the workbook and selecting OK. The macro works well without the If/Else element.



Sub RefreshData()
'
'RefreshData Macro
'Unprotect, Refresh Data, Protect
'
Application.ScreenUpdating = False

With Sheet4
.Protect Password:="password", UserInterfaceOnly: = True

ThisWorkbook.UpdateLink Name:=ThisWorkbook.LinkSources

If ......... = False Then
' Cancel was selected and Data Not Refreshed
Else
' OK was selected and Data Refreshed
End If

End With

End Sub

Aucun commentaire:

Enregistrer un commentaire