On Tue, 16 Dec 2003 16:58:01 -0800, <an*******@discussions.microsoft.com> wrote:
¤ Morten,
¤
¤ Thank you for such a quick response. I tried your
¤ suggestion and had no success. What's odd is that this
¤ approach works if I replaced "excel.application"
¤ with "word.application" or "access.application". I
¤ wonder if this has something to do with my installation
¤ of Excel. But what's also odd is that the quit method
¤ works for Excel if I run it from an older version of vb.
¤ It's just not working for vb .net 2003.
¤
¤ Below is the code. Would appreciate any insights.
¤
¤ Function validfile(ByVal in_file As String) As Boolean
¤
¤ Dim excel As Object
¤
¤ On Error Resume Next
¤ validfile = True
¤ excel = GetObject(, "excel.application")
¤ If Err().Number <> 0 Then
¤ excel = CreateObject("excel.application")
¤ b_excelwasnotrunning = True
¤ Err().Clear() ' Clear Err object in case
¤ error occurred.
¤ Else
¤ b_excelwasnotrunning = False
¤ End If
¤ excel.Workbooks.Open(in_file)
¤ If Err().Number <> 0 Then
¤ validfile = False
¤ Err().Clear()
¤ End If
¤ If b_excelwasnotrunning = True Then
¤ excel.quit()
¤
¤ System.Runtime.InteropServices.Marshal.ReleaseComO bject
¤ (excel)
¤ excel = Nothing
¤ End If
¤
¤
¤ End Function
¤
¤ Thank you for any additional help.
¤
¤ Regards,
¤ Mike Sweet
Try not to create implicit objects. For example, if you create a Workbook object by opening a
Workbook, set the returned object to a variable:
ExcelWorkbook = excel.Workbooks.Open(in_file)
ExcelWorkbook.Close, False
ExcelWorkbook = Nothing
Paul ~~~
pc******@ameritech.net
Microsoft MVP (Visual Basic)