View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Object required confusion

Rob is absolutely correct - and I missed that

? typename(wb.Worksheets("MASTER").Copy(After:=wb.Sh eets(wb.Sheets.Count)))
Boolean

But that would give a type mismatch error I think (at least in Excel 97 it
does).

So you may still have problems with wb in addition to that. A possible
revision

' wb refers to the workbook where n copies of
' "master" are created
set wb = workbooks("somebook.xls")
For Each ws In Workbooks(SourceWorkbook).Worksheets
With ws
If Not (UCase(.Name) = "MASTER") Then
wb.Worksheets("MASTER").Copy(After:= _
wb.Sheets(wb.Sheets.Count))
ActiveSheet.Name = ws.Name
end if
End With
Next

--
Tom Ogilvy


Tom Ogilvy wrote in message
...
is wb set to a workbook.

Also, if you are going to use wb explicitly in each instance, you don't

need
the with wb statement.
'
' wb refers to the workbook where n copies of
' "master" are created
set wb = workbooks("somebook.xls")
For Each ws In Workbooks(SourceWorkbook).Worksheets
With ws
If Not (UCase(.Name) = "MASTER") Then
Set ws2 = wb.Worksheets("MASTER").Copy(After:= _
wb.Sheets(wb.Sheets.Count))
ws2.Name = ws.Name
end if
End With
Next

Regards,
Tom Ogilvy


Stuart wrote in message
...
In the following I receive an 'Object required' error
on the line 'Set ws2 etc'. Why is this, please?

For Each ws In Workbooks(SourceWorkbook).Worksheets
With ws
If Not (UCase(.Name) = "MASTER") Then
With wb
Set ws2 = wb.Worksheets("MASTER").Copy(After:= _
wb.Sheets(wb.Sheets.Count))
ws2.Name = ws.Name
etc

The copy is made when stepping through, but only after the
error message is displayed.

Regards.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.500 / Virus Database: 298 - Release Date: 10/07/2003