Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default trouble adding a name...

When I open a workbook, I have code to check all of the worksheets to see if
they have already been "formatted", if not I run code to do so... (new
worksheets are added to the workbook by an external program, and need to be
reformatted into a legible worksheet)
A range name is added to each worksheet to flag it as having been
reformatted (ReformattingComplete = True...) The new sheets do not have the
name; it is added by code (which is where i might be having my problem....

On a new sheet, with no range named (ReformattingComplete) it gets stuck in
an endless loop at the error handler...

any suggestions would be much appreciated,
mark


Private Sub Workbook_Open()
For Each Sheet In Worksheets
If Sheet.Name < "QuickBooks Export Tips" _
And Sheet.Name < "Billing Rates" _
And Sheet.Name < "Project Upset" Then
Worksheets(Sheet.Name).Activate
ReformatWorksheet 'call subroutine to verify formatting
status
End If
Next Sheet
End Sub

------------------------------------------------
Sub ReformatWorksheet()
On Error GoTo errNoNameFound ' new sheets will not have a named range
"ReformatingCompleted"
If ActiveWorkbook.ActiveSheet.Names("ReformatingCompl eted").Value =
"=TRUE" Then
Exit Sub
End If
FormatandAddFormulas 'subrouting to reformat sheet is called
....
errNoNameFound: ' Error-handling routine
ActiveWorkbook.ActiveSheet.Names.Add Name:="ReformatingCompleted",
RefersToR1C1:=False 'add named reange and assign false value


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default trouble adding a name...

Have a go with the following -

Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Select Case ws.Name
Case "QuickBooks Export Tips", "Billing Rates", "Project Upset"
Case Else
ReformatWorksheet ws
End Select
Next ws
End Sub

Sub ReformatWorksheet(ws As Worksheet)
Dim nm As Name
On Error Resume Next
Set nm = ws.Names("ReformatingCompleted")
If nm Is Nothing Then
Set nm = ws.Names.Add("ReformatingCompleted", False)

ElseIf UCase$(nm.Value) = "=TRUE" Then
Exit Sub
End If
On Error GoTo errNoNameFound

FormatandAddFormulas ws ' pass the worksheet object
nm.Value = True

Exit Sub

errNoNameFound: ' Error-handling routine
If Not nm Is Nothing Then
nm.Value = False
Else
' shouldn't get this
MsgBox Err.Description
End If

End Sub

Sub FormatandAddFormulas(ws As Worksheet)
ws.Range("A1").Interior.ColorIndex = 6

End Sub

I'd suggest you put ReformatWorksheet & FormatandAddFormulas in a normal
module then you can use the same routines, don't forget to pass a reference
to the worksheet, eg ws or activesheet or worksheets("sheetname").

Regards,
Peter T


"Mark Kubicki" wrote in message
...
When I open a workbook, I have code to check all of the worksheets to see
if they have already been "formatted", if not I run code to do so... (new
worksheets are added to the workbook by an external program, and need to
be reformatted into a legible worksheet)
A range name is added to each worksheet to flag it as having been
reformatted (ReformattingComplete = True...) The new sheets do not have
the name; it is added by code (which is where i might be having my
problem....

On a new sheet, with no range named (ReformattingComplete) it gets stuck
in an endless loop at the error handler...

any suggestions would be much appreciated,
mark


Private Sub Workbook_Open()
For Each Sheet In Worksheets
If Sheet.Name < "QuickBooks Export Tips" _
And Sheet.Name < "Billing Rates" _
And Sheet.Name < "Project Upset" Then
Worksheets(Sheet.Name).Activate
ReformatWorksheet 'call subroutine to verify formatting
status
End If
Next Sheet
End Sub

------------------------------------------------
Sub ReformatWorksheet()
On Error GoTo errNoNameFound ' new sheets will not have a named range
"ReformatingCompleted"
If ActiveWorkbook.ActiveSheet.Names("ReformatingCompl eted").Value =
"=TRUE" Then
Exit Sub
End If
FormatandAddFormulas 'subrouting to reformat sheet is called
...
errNoNameFound: ' Error-handling routine
ActiveWorkbook.ActiveSheet.Names.Add Name:="ReformatingCompleted",
RefersToR1C1:=False 'add named reange and assign false value



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
trouble adding addins jc Excel Discussion (Misc queries) 0 December 23rd 09 12:15 AM
trouble adding addins jc Excel Discussion (Misc queries) 0 December 23rd 09 12:13 AM
Trouble with VB since adding a macro Susan Excel Programming 1 April 11th 06 05:13 PM
trouble adding to list. jeramie[_2_] Excel Programming 2 March 13th 06 08:31 AM
I am having trouble adding a row in Excel. What am i doing wrong? Glendie Excel Worksheet Functions 1 May 28th 05 08:37 PM


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