You haven't Set the wb object or was that done in another procedure? Where are those Dim statements located - not in the procedure you posted.

Should add Option Explicit to the top of all modules.