ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Why do I get an error in this code??? (https://www.excelbanter.com/excel-programming/415861-why-do-i-get-error-code.html)

Charlotte E.

Why do I get an error in this code???
 
Why do I get an error in the third line of this little code:

Dim WS As Worksheet
Dim WB As Workbook

WB = ThisWorkbook
For Each WS In WB.Worksheets


????




Bernie Deitrick

Why do I get an error in this code???
 
WB is an object, so use

Set WB = ThisWorkbook

HTH,
Bernie
MS Excel MVP


"Charlotte E." wrote in message ...
Why do I get an error in the third line of this little code:

Dim WS As Worksheet
Dim WB As Workbook

WB = ThisWorkbook
For Each WS In WB.Worksheets


????






Gary Keramidas

Why do I get an error in this code???
 
workbook is an object so use this:

Set WB = ThisWorkbook

--


Gary


"Charlotte E." wrote in message
...
Why do I get an error in the third line of this little code:

Dim WS As Worksheet
Dim WB As Workbook

WB = ThisWorkbook
For Each WS In WB.Worksheets


????






Charlotte E.

Why do I get an error in this code???
 
Thanks to both Bernie and Gary :-)



"Gary Keramidas" <GKeramidasATmsn.com skrev i en meddelelse
...
workbook is an object so use this:

Set WB = ThisWorkbook

--


Gary


"Charlotte E." wrote in message
...
Why do I get an error in the third line of this little code:

Dim WS As Worksheet
Dim WB As Workbook

WB = ThisWorkbook
For Each WS In WB.Worksheets


????









All times are GMT +1. The time now is 02:46 PM.

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