Adding a new sheet (no focus)

S

SOS

Hi all,

I have a workbook with a sheet called "Master" and I am using th
following line of code to add a new sheet called "Test" (if "Test" doe
not already exist) :

Sheets.Add.Name = "Test"

Is it possible to add this new sheet WITHOUT Excel automatically makin
that the active sheet.

TIA

Seamu
 
H

Harald Staff

Hi Seamus

Don't think so. Here's a workaround:

Sub test()
Dim S As Worksheet, T As Worksheet
Set S = ActiveSheet
On Error Resume Next
Application.ScreenUpdating = False
Set T = Sheets.Add
T.Name = "Test"
T.Move after:=Worksheets(ActiveWorkbook.Worksheets.Count)
S.Activate
Application.ScreenUpdating = True
End Sub

HTH. best wishes Harald
 
Top