View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Bizarre macro problem

I think it was the combination of doEvents and releasing the shiftkey.

Andy wrote:

Hi Tony

Your first suggestion works!!! In fact I only needed to add DoEvents before
opening the workbook.

Out of interest I tried error trapping but that didn't work.

Thank you all sooooo much for your help and for maintaining my sanity!
Andy

"tony h" wrote:


two suggestions

1. try using a doevents just before and after your troublesome line.
The doEvents statement tell excel to stop doing what it is doing and
let other processes have a go. It maybe that your breakpoint is just
releasing the process and that the doevents would do the same thing.

2. Put an error trap around the code. depending on how the code was
activated an error may just halt the code. It is particularly important
to do this in user defined functions and dependant code that is called
from the worksheet.

Sub mycode()

Dim str As String

On Error GoTo AnError

'my code ...........
str = 1 / 0

GoTo TheEnd
AnError:
MsgBox "error : " & Err.Number & " " & Err.Description
Stop 'you will have to decide what to do here
TheEnd:

End Sub

hope this helps


--
tony h
------------------------------------------------------------------------
tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
View this thread: http://www.excelforum.com/showthread...hreadid=392442



--

Dave Peterson