LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stepping through Code Jim May Excel Discussion (Misc queries) 9 October 25th 07 01:40 PM
How do I get post-hoc results after running an ANOVA in Excel? Stephanie West Excel Discussion (Misc queries) 0 August 1st 07 10:16 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 7 March 7th 05 06:29 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 0 February 28th 05 06:26 PM
keep a running total of my formula results after each (F9) Souvien Excel Discussion (Misc queries) 1 January 23rd 05 01:59 AM


All times are GMT +1. The time now is 03:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"