View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Help with C. Pearsons code to VBE

Hi Les,

I'm not quite sure what's going on, in particular the hanging around bit
followed by the problem msg and quit. However if(?) you add a new sheet
with the VBE closed you won't be able to return it's codename until after
saving and reopening the file, - or - trying any one of a number of tricks.
If you've merely failed to return the codename I'd only expect the code to
fail with an error normal message, unlike what you've described (unless of
course you've got more code trying to run beyond what you've posted).

Here's one way that might be viable for you, particularly as your insert
code will end up with the VBE open in front of the user (nice to close it
when done)

include following towards the top of your procedure, actually it could
replace the line
' sh = ActiveWorkbook.ActiveSheet.CodeName

If GetCodeNameOpenVBE(ActiveSheet, sh) = False Then
Application.Goto "CreateEventProcedure"
MsgBox "Please run CreateEventProcedure"
Exit Sub
End If

and this function -

Function GetCodeNameOpenVBE(sht As Object, sName As String) As Boolean
Dim cbb As CommandBarButton

sName = sht.CodeName
If Len(sName) = 0 Then
Set cbb = Application.CommandBars.FindControl(ID:=1695)
If Not cbb Is Nothing Then
cbb.Execute
sName = sht.CodeName
End If
End If
GetCodeNameOpenVBE = Len(sName) 0
End Function

All it does is open the VBE, after which normally the codename of the new
sheet can be returned.

Regards,
Peter T

"Les Stout" wrote in message
...
Hi Peter T, i even tried saving it first but still get the message. It
puts the code into the sheet but then hangs for a while and then the
message pops up.



Best regards,

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***