Thread: workbook
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Sam Wilson Sam Wilson is offline
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'