Question : invalid case exception occurred, specified cast not valid.

Hello experts,

Need some assistance determining how to fix this error.   Please advise if you have any insight.   Thanks

Getting error at this line of code (see code snippet):
objSourceWB.Close()

Error:
Invalid Case Exception occurred
specified cast is not valid
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
RELEVANT LINES OF CODE:

Dim strSourceTab = "DRS"
Dim strSrcFile = "DRS.csv"
....
....
....

objSourceExcel = CreateObject("Excel.Application")
objSourceWB = objSourceExcel.WorkBooks.Open(strSrcDirectory & strSrcFile)
objSourceWS = objSourceExcel.ActiveWorkBook.WorkSheets(strSourceTab)
objSourceWS.Activate()
objWriter.WriteLine("file opened for Read.")
...
...
objSourceWB = objSourceExcel.WorkBooks.Open(strSrcDirectory & strSrcFile)
....
...
...
objSourceWB.Close()

Answer : invalid case exception occurred, specified cast not valid.

OK sorry, please ignore this question.    

I'm not sure why but I realized that objSourceWB.Close() doesn't work.

I set objSourceWB = Nothing and that fixed it.  
Random Solutions  
 
programming4us programming4us