Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Stepping through code gives different results than running it!
Hi, I have some very simple VBA6 code, which gives an error when run. But when I step through it, it runs fine without giving the error! More specifically, the code is trying to un-protect a worksheet, then refresh a DataQuery on the worksheet, then protect the worksheet again. The code is: ------------------------------------------------ Public Sub refreshAll() Dim timeSheet As Worksheet Dim protectionDrawingObjectsState As Boolean Dim protectionContentsState As Boolean Dim protectionScenariosState As Boolean Dim protectionUIState As Boolean On Error GoTo ErrHandler // Break here Set timeSheet = ActiveWorkbook.Sheets("Timesheet") ' Temporarily unprotect the time sheet protectionDrawingObjectsState = timeSheet.ProtectDrawingObjects protectionContentsState = timeSheet.ProtectContents protectionScenariosState = timeSheet.ProtectScenarios protectionUIState = timeSheet.ProtectionMode timeSheet.Unprotect (PROTECTION_PASSWORD) ' Refresh all the query tables ActiveWorkbook.refreshAll ' Restore protection and exit GoSub RestoreProtection Exit Sub RestoreProtection: Call timeSheet.Protect(PROTECTION_PASSWORD, protectionDrawingObjectsState, protectionContentsState, protectionScenariosState, protectionUIState) Return ErrHandler: GoSub RestoreProtection MsgBox Err.Description Exit Sub End Sub ------------------------------------------------ There is only one data query in the workbook, and it is on the Timesheet sheet. If I break at the top, and then step through it (with Shift F8), it works fine - the data query gets refreshed, and the sheet returns to its protected state. If I break at the top, then run (with F5), it gives the following error: "The cell or chart you are trying to change is protected and therefore read-only. To modify a protected cell or chart, first remove the protection ... etc." Please help - I don't understand why, if there is a problem, I don't get the error while stepping through. Thanks for any advice, Simon. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Stepping through Code | Excel Discussion (Misc queries) | |||
How do I get post-hoc results after running an ANOVA in Excel? | Excel Discussion (Misc queries) | |||
Error trapped only while stepping through the code - Not triggered when run | Excel Discussion (Misc queries) | |||
Error trapped only while stepping through the code - Not triggered when run | Excel Discussion (Misc queries) | |||
keep a running total of my formula results after each (F9) | Excel Discussion (Misc queries) |