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: 454
Default Inserting Code within ThisWorkbook via Code Q

I have the following Code that that works great under Office XP/2003
versions except one problem PC that uses Office XP and Windows 2000. I
have a Reference set to Microsoft VBA Extensibility v 5.3. Is there an
issue with running code via VBA to insert Code into ThisWorkbook under
Win2000?

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal ClassName As String, ByVal WindowName As String) As Long
Private Declare Function LockWindowUpdate Lib "user32" _
(ByVal hWndLock As Long) As Long

Sub Populate_TW_2()

Dim StartLine As Long
Dim msg1 As String, msg2 As String

Dim VBEHwnd As Long
On Error GoTo ErrH:
Application.VBE.MainWindow.Visible = False
VBEHwnd = FindWindow("wndclass_desked_gsk", _
Application.VBE.MainWindow.Caption)
If VBEHwnd Then
LockWindowUpdate VBEHwnd
End If

msg1 = "Worksheets(""View"").Visible = True" & vbCr & _
"Dim sh As Worksheet" & vbCr & _
"For Each ws In Worksheets " & vbCr & _
"If ws.Name = ""View"" Then"

msg2 = "ws.Visible = True" & vbCr & _
"Else" & vbCr & _
"ws.Visible = xlVeryHidden" & vbCr & _
"End If" & vbCr & _
"Next"


With ActiveWorkbook.VBProject.VBComponents("ThisWorkboo k").CodeModule
StartLine = .CreateEventProc("BeforeClose", "Workbook") + 1
..InsertLines StartLine, msg1 & vbCr & msg2
End With
Application.VBE.MainWindow.Visible = False
ErrH:
LockWindowUpdate 0&
End Sub

 
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
Populate ThisWorkbook via Code Sean Excel Programming 13 January 14th 07 06:03 PM
inserting code into code module crashes Kris Excel Programming 8 January 25th 06 05:28 PM
Deleting Code in 'ThisWorkbook' Ken Loomis Excel Programming 4 March 25th 05 01:36 PM
Importing Code into 'ThisWorkbook' Mark Excel Programming 3 April 16th 04 03:29 PM
Delete the code in ThisWorkbook Darrin Henry Excel Programming 1 October 1st 03 11:10 PM


All times are GMT +1. The time now is 08:09 AM.

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

About Us

"It's about Microsoft Excel"