ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding a new sheet (no focus) (https://www.excelbanter.com/excel-programming/308877-adding-new-sheet-no-focus.html)

SOS[_26_]

Adding a new sheet (no focus)
 
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

--
Message posted from http://www.ExcelForum.com


Harald Staff

Adding a new sheet (no focus)
 
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

"SOS " skrev i melding
...
Hi all,

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

Sheets.Add.Name = "Test"

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

TIA

Seamus


---
Message posted from http://www.ExcelForum.com/




SOS[_27_]

Adding a new sheet (no focus)
 
Thanks Harald,

I'll give that a try

Seamu

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 01:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com