Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default Trying To Push Code For Worksheet_Change Into VBA-Created Workbook?

Per (PeteCresswell):
My playpen (in an MS Access application) includes this code,
which succeeds in pushing the desired event routine
into "Module1"... but it seems to me like I need it in
"ThisWorkbook".


I figured it out ("stumbled onto something that seems to work" is
probably a more accurate use of the language...).

Turns out that even though the sheet I'm creating is named "BBB"
by Yours Truly, it's known to the VBA code as "Sheet1" - even
after we have explicitly deleted "Sheet1".

viz:
================================================== =============
' ---------------------------------------------------
' Create a workbook and the sheet we are going to
' populate

2020 With mySS
2021 .Workbooks.Add
2022 Set myWS = .Worksheets.Add
2023 End With
2029 myWS.Name = "BBB"

' ------------------------------------------------
' Remove any default sheets that the user's Excel
' defaults may have created

DoCmd.SetWarnings False
On Error Resume Next
With mySS
.Worksheets("Sheet1").Delete
.Worksheets("Sheet2").Delete
.Worksheets("Sheet3").Delete
End With
On Error GoTo 0
DoCmd.SetWarnings True

' ---------------------------------------------------
' ATTEMPT TO PUSH SOME EVENT CODE

2410 Set myWB = myWS.Parent
2420 Set myParentModule = myWB.VBProject.VBComponents("Sheet1")
2430 Set myCodeModule = myParentModule.CodeModule

2440 With myCodeModule
2441 .InsertLines .CountOfLines + 1, myCode
2449 End With
================================================== =============
--
PeteCresswell
Reply
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
Push updates from one workbook to others? ChrisP Excel Worksheet Functions 1 July 11th 08 05:25 PM
EXCEL: VBE code for a push-down stack (Date,Value1,.....) Joe Bailey[_2_] Excel Programming 3 September 4th 06 10:01 PM
need help with Worksheet_Change code Alex Excel Programming 6 August 14th 06 08:38 PM
Worksheet_Change even code will not run retseort[_13_] Excel Programming 3 November 28th 05 10:35 PM
Adding Code to the This_workbook module of a created workbook RPIJG[_68_] Excel Programming 1 July 9th 04 06:35 PM


All times are GMT +1. The time now is 06:28 PM.

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"