Dave,
Thanks for the suggestion, but accessing any property of
Application.VBE results in the error "Programmatic access
to Visual Basic Project is not trusted" in Excel 2002. I
don't want to require users of my Add-In to lower their
security simply so that my Add-In works properly.
Bob
-----Original Message-----
Yep. I see it.
In fact, I think it's been a problem for awhile (since
xl97 at least). I used
to have a routine that was based on David McRitchie's
Table of contents
(http://www.mvps.org/dmcritchie/excel/buildtoc.htm) and
I wanted to print the
codename. But the added worksheet's codename never
would appear.
(I just dumped the codename--it wasn't important enough
to me to keep.)
But maybe you could use something like this:
In a general module:
Option Explicit
Private Declare Function LockWindowUpdate Lib "USER32" _
(ByVal hwndLock As Long) As Long
Private Declare Function GetDesktopWindow Lib "USER32"
() As Long
Sub WindowUpdating(Enabled As Boolean)
'Completely Locks the Whole Application Screen Area,
'including dialogs and the mouse.
Dim Res As Long
If Enabled Then
LockWindowUpdate 0
'Unlock screen area
Else
Res = LockWindowUpdate(GetDesktopWindow)
'Lock at desktop level
End If
End Sub
Sub testme01()
With Application.VBE.MainWindow
Call WindowUpdating(False)
.Visible = True
.Visible = False
Call WindowUpdating(True)
End With
MsgBox ActiveWorkbook.ActiveSheet.CodeName
End Sub
But SAVE your work before you run it (in every open
application!).
The windowupdating stuff actually freezes the pc. If
something bad happens,
you'll have to reboot.
(application.screenupdating stops excel from flickering,
but doesn't have any
affect on other applications (like the VBE--kind of
another app.))
(If I get industrious, I may add it to my stolen version
of David McRitchie's
code.)
And it seemed to work ok for me under win98 and xl2002.