View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default ~~ Help with Userform and Combo Box ~~

This is the portion that names the new sheet:

With NewWks
.Name = Me.ComboBox1.Value '<--- this line does the rename
.Range("B3").Value = NewWksName
End With

But I'm not sure what the error is on that other line.

Any chance you're saving to a location that you don't have write access to?

Corey wrote:

Thanks for the replay Dave,

I have input the code, but get an error at the <== line :

With NewWkbk 'either the new workbook or the activeworkbook
Set NewWks = Nothing
On Error Resume Next
Set NewWks = .Worksheets(NewWksName)
On Error GoTo 0
If NewWks Is Nothing Then
'doesn't already exist
'keep going
.Worksheets("1").Copy After:=.Worksheets(.Worksheets.Count)
Set NewWks = ActiveSheet
With NewWks
.Name = Me.ComboBox1.Value
.Range("B3").Value = NewWksName
End With
'save the new workbook here
Application.DisplayAlerts = False
.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal
<================= ERROR ===========
Application.DisplayAlerts = True
Else
MsgBox "Worksheet named: " & NewWksName & " already exists." _
& vbLf & "Try again"
End If
End With
End Sub

I think this is where the New WorkBook should be Named.
THIS is ONLY Needed when the Maximum Number of sheets has reached 10.
ELSE a New WorkSheet is created in the active workbook.

Corey....


--

Dave Peterson