Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Possible to remove Workbook window title bar? Or other ways toarrange multiple workbook windows. | Excel Programming | |||
Copy Autofilter Source Workbook A result in Destination Workbook BSheet1 | Excel Programming | |||
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook | Excel Programming | |||
Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ?? | Excel Programming | |||
What commands do you use to name a workbook, save a workbook,open a workbook | Excel Programming |