Sheet(CaseName).Delete Error 13 type mismatch

  • Thread starter Thread starter M Skabialka
  • Start date Start date
M

M Skabialka

From Access:
CaseName = "Dallas"
xlApp.Run "ExtractData", CaseName

In Excel:
ExtractData(CaseName)

This gives me an error 13 - type mismatch:
Sheet(CaseName).Delete

But this doesn't:
Sheets("Dallas").Delete

I think
Sheet(CaseName) is looking for a number not a string. How do I convince it
otherwise?

Thanks,
Mich
 
Is it a typo that you've got Sheet(CaseName).Delete and not
Sheets(CaseName).Delete?

Have you declared CaseName as String in Excel?
 
Typo - but your next comment helped me fix the problem in the declaration of
the sub:

Sub ExtractData(CaseName As String)
Sheets(CaseName).Delete
Sheets.Add.Name = CaseName
....
End Sub

Thanks - I didn't want to have to change the code every time we got a new
case!

Mich
 
Back
Top