View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dick Kusleika[_3_] Dick Kusleika[_3_] is offline
external usenet poster
 
Posts: 599
Default Getting VBE to recognize a new sheet

quartz

Here's how I would do it. You can compare this to what you have

Sub MakeNewSheetCode()

Dim sh As Worksheet
Dim Vbc As VBComponent

On Error Resume Next
Application.DisplayAlerts = False
ThisWorkbook.Sheets("Report").Delete
Application.DisplayAlerts = True
On Error GoTo 0

Set sh = ThisWorkbook.Worksheets.Add
sh.Name = "Report"

Set Vbc = ThisWorkbook.VBProject.VBComponents(sh.CodeName)

With Vbc.CodeModule
.CreateEventProc "Change", "Worksheet"
.InsertLines .ProcBodyLine("Worksheet_Change", _
vbext_pk_Proc) + 1, "Call MySub"
End With


End Sub

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"quartz" wrote in message
...
Sorry,

I should have added that depending upon how I structure my code, I do get

a subscript error on the sheet, as though it doesn't exist or can't be
found. This error is incurred AFTER the program has already replaced the
sheet AND written data into it!

Again thanks for your assistance, I do hope you or someone posts back...