#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default workbook

Hi,

i hv a excel workbook called as Raw.xls, i need a macro code to check in
Raw.xls whether the sheet name 'Cat' is there, if not there then the macro
need to add a new sheet called as 'Cat'
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default workbook

Hi Ranjith

Try the below macro...Edit the file path to suit

Sub AddSheet()
Dim wb As Workbook, ws As Worksheet
Set wb = Workbooks.Open("c:\raw.xls")
On Error Resume Next
Set ws = wb.Sheets("Cat")
If ws Is Nothing Then
Set ws = wb.Worksheets.Add(after:=wb.Sheets(wb.Sheets.Count ))
ws.Name = "Cat"
End If
wb.Close True
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Ranjith Kurian" wrote:

Hi,

i hv a excel workbook called as Raw.xls, i need a macro code to check in
Raw.xls whether the sheet name 'Cat' is there, if not there then the macro
need to add a new sheet called as 'Cat'

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default workbook

thanks a lot

"Jacob Skaria" wrote:

Hi Ranjith

Try the below macro...Edit the file path to suit

Sub AddSheet()
Dim wb As Workbook, ws As Worksheet
Set wb = Workbooks.Open("c:\raw.xls")
On Error Resume Next
Set ws = wb.Sheets("Cat")
If ws Is Nothing Then
Set ws = wb.Worksheets.Add(after:=wb.Sheets(wb.Sheets.Count ))
ws.Name = "Cat"
End If
wb.Close True
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Ranjith Kurian" wrote:

Hi,

i hv a excel workbook called as Raw.xls, i need a macro code to check in
Raw.xls whether the sheet name 'Cat' is there, if not there then the macro
need to add a new sheet called as 'Cat'

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default workbook

Sub cus()
For Each Sheet In Workbooks("Raw.xls").Sheets
If Sheet.Name = "Cat" Then cnt = cnt + 1
Next

If cnt = 0 Then Sheets.Add
ActiveSheet.Name = "Cat"

End Sub


On 12 Lis, 11:34, Ranjith Kurian
wrote:
Hi,

i hv a excel workbook called as Raw.xls, i need a macro code to check in
Raw.xls whether the sheet name 'Cat' is there, if *not there then the macro
need to add a new sheet called as 'Cat'


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default workbook

Sub demo()

Dim wb As Workbook
Dim ws As Worksheet

Dim bFlag As Boolean
bFlag = False

'You only need one of the two following lines - 1st if it's already open,
2nd if it isn't
Set wb = Workbooks("Raw.xls")
Set wb = Workbooks.Open("C:\path\Raw.xls")

For Each ws In wb.Worksheets
If ws.Name = "Cat" Then bFlag = True
Next ws

If bFlag = False Then
Set ws = wb.Worksheets.Add
ws.Name = "Cat"
End If

End Sub

"Ranjith Kurian" wrote:

Hi,

i hv a excel workbook called as Raw.xls, i need a macro code to check in
Raw.xls whether the sheet name 'Cat' is there, if not there then the macro
need to add a new sheet called as 'Cat'



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to remove Workbook window title bar? Or other ways toarrange multiple workbook windows. minimaster Excel Programming 4 September 15th 09 11:47 AM
Copy Autofilter Source Workbook A result in Destination Workbook BSheet1 u473 Excel Programming 1 September 9th 08 05:14 PM
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook burl_rfc Excel Programming 1 April 1st 06 08:48 PM
Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ?? WimR Excel Programming 9 July 25th 05 12:44 PM
What commands do you use to name a workbook, save a workbook,open a workbook Steven R. Berke Excel Programming 1 July 24th 03 11:37 PM


All times are GMT +1. The time now is 07:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"