Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Getting VBE to recognize a new sheet

Hello, HELP!

Each time my program runs, it replaces an existing "REPORT" sheet with a new one. The program then writes VBA into the newly created sheet module. This program runs fine the first time (i.e. when there is no pre-existing "REPORT" sheet).

If there is a pre-existing "REPORT" sheet, the program explodes (and I am in the blast radius).

The problem is, I think, that the portion of the program that writes the code into the module sheet does not yet see or recognize that the new "REPORT" sheet exists yet (even though it actually does).

How can I overcome this situation and make it see the new sheet on the fly?

Thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Getting VBE to recognize a new sheet

quartz,

Usually, it is solved by starting off with something like

On Error Resume Next
Application.DisplayAlerts = False
Worksheets("REPORT").Delete
.....
'code to add the new REPORT sheet
.......
Application.DisplayAlerts = True

HTH,
Bernie
MS Excel MVP

"quartz" wrote in message
...
Hello, HELP!

Each time my program runs, it replaces an existing "REPORT" sheet

with a new one. The program then writes VBA into the newly created
sheet module. This program runs fine the first time (i.e. when there
is no pre-existing "REPORT" sheet).

If there is a pre-existing "REPORT" sheet, the program explodes (and

I am in the blast radius).

The problem is, I think, that the portion of the program that writes

the code into the module sheet does not yet see or recognize that the
new "REPORT" sheet exists yet (even though it actually does).

How can I overcome this situation and make it see the new sheet on

the fly?

Thanks in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Getting VBE to recognize a new sheet

Bernie,

Thanks for responding, but actually my code is already structured similarly to the way you suggested.

I don't get a normal trappable error, I get a fatal error that causes Excel to shut down altogether.

Sometimes my code actually succeeds before it dies, other times, it doesn't write the code into the module when the error occurs.

Any other ideas???

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Getting VBE to recognize a new sheet

quartz,

Sounds like it is time to:

1) Use Rob Bovey's code cleaner utility

2) If that doesn't work, start from a new workbook and rebuild your
application (unfortunately, it sounds like it is corrupted)

HTH,
Bernie
MS Excel MVP

"quartz" wrote in message
...
Bernie,

Thanks for responding, but actually my code is already structured

similarly to the way you suggested.

I don't get a normal trappable error, I get a fatal error that

causes Excel to shut down altogether.

Sometimes my code actually succeeds before it dies, other times, it

doesn't write the code into the module when the error occurs.

Any other ideas???



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Getting VBE to recognize a new sheet

Rebuilt the file from scratch. Same behaviour.

Running the code inside the VBE does not generate any error.

Running it as the user would from the App generates the error.


  #6   Report Post  
Posted to microsoft.public.excel.programming
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...



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
sum to recognize new rows deb Excel Discussion (Misc queries) 3 January 27th 10 09:50 PM
trying to get sheet 1 to recognize and move student names to pg 2 vaughn01 Excel Worksheet Functions 1 December 14th 09 08:30 PM
How do I link cells, sheet to sheet, to recognize row deletions? LeeC Excel Discussion (Misc queries) 30 November 6th 09 10:26 PM
How recognize sheet protected? John Excel Worksheet Functions 1 March 3rd 06 08:43 PM
Recognize #div/0! JOn Kunces via OfficeKB.com Excel Discussion (Misc queries) 1 July 14th 05 04:18 PM


All times are GMT +1. The time now is 06:53 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"