Avoid VBA errors with the same page name

knaabis

Active Member
Joined
Apr 25, 2006
Messages
254
Office Version
  1. 2013
Platform
  1. Windows
How to integreate in this VBA - when I try to create a page by the existing name, then that VBA is suspended?

Sub SheetNumber()
DialogSheets("Dialog1").Show
Sheets.Add.Name = DialogSheets("Dialog1").EditBoxes("4").Text
With DialogSheets("Dialog1")
.EditBoxes("4").Text = ""
End With
End Sub
 
That, once again, is the same question you have already had answered.
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Knaabis

Can you explain what the overall purpose of this code is?

We know you are creating worksheets, but why?

Also why are you allowing existing names to be used in the first place?:)

As for the code to check for the sheet name existing what you should do is add a worksheet without a name, ie allow Excel to give it a name (eg Sheet9, Sheet5...

Then, and only then try and rename it.
Code:
Dim wsNew As Worksheet
Dim strName As String
    Set wsNew = Worksheets.Add
 
    On Error Resume Next
 
     strName = DialogSheets("Dialog1").EditBoxes("4").Text
 
     wsNew.Name = strName
 
     On Error GoTo 0
 
     MsgBox "There is already a worksheet with the name " & strName
This worked for me, and I even created a Dialog Sheet, for fun.:)

Why don't you use a UserForm, all the rage apparently.
 
Upvote 0

Forum statistics

Threads
1,214,974
Messages
6,122,536
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top