Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

macro

Status
Not open for further replies.

workshop

Technical User
Nov 9, 2001
55
0
0
US
I need help... I try to using the macro on excel and in the script include open new worksheet, so when I execcute it give me debug at Windows("Book23").Activate I have to change the book to one numer ahead to make it work.
what should I change so it work and I don't have to debug every time...
Thanks in advance
 
If you use something similar to this macro code to create the sheet, you can know what the name is:
Code:
Option Explicit

Sub Demo()
Dim sNewName As String
  InsertNewSheet sNewName
  MsgBox sNewName
End Sub

Sub InsertNewSheet(NewSheetName As String)
  ActiveWorkbook.Sheets.Add Before:=Worksheets(1)
  NewSheetName = Worksheets(1).Name
End Sub

You can build from here either by passing in a parameter to indicate where to insert, or simply move the new sheet to wherever you want it to go after creating it in front.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top