Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am using VB.Net (2.0) to automate MS-Excel.
In the Class, I decla Private oXL As Microsoft.Office.Interop.Excel.Application = Nothing Private oWB As Microsoft.Office.Interop.Excel.Workbook = Nothing Private oWS As Microsoft.Office.Interop.Excel.Worksheet = Nothing I open the WorkBook when I get an instance of this class: Public Sub New(Optional ByVal SourceFile As String = "", Optional ByVal ActivateWorkSheetNamed As String = "", Optional ByVal SetVisible As Boolean = False) oXL = New Microsoft.Office.Interop.Excel.Application oXL.DisplayAlerts = SetVisible oXL.Visible = SetVisible If (SourceFile.Trim.Length 0) Then If File.Exists(SourceFile) Then oWB = oXL.Workbooks.Open(SourceFile, False, False) Else If oXL.Workbooks.Count < 1 Then oWB = oXL.Workbooks.Add() ElseIf oXL.Workbooks.Count = 1 Then oWB = oXL.Workbooks(1) End If oXL.SaveWorkspace(SourceFile) End If End If If (oXL.Workbooks.Count < 1) Then oXL.Workbooks.Add() oWB = oXL.Workbooks(1) End If oWS = oWB.ActiveSheet If ActivateWorkSheetNamed.Trim.Length 0 Then Dim I As Integer = 1 For I = 1 To oWB.Worksheets.Count If oWB.Worksheets(I).Name.ToString.ToUpper = ActivateWorkSheetNamed.ToUpper Then oWS = oWB.Worksheets(ActivateWorkSheetNamed) End If Next End If End Sub I am getting the above error when calling the following code from my application, at the line with "-": Public Function WorkBookExists(ByVal WorkBookName As String) As Boolean Dim I As Integer = 0 WorkBookExists = False - For Each oWB In oXL.Workbooks If (WorkBookName.Trim.ToUpper = oWB.Name.Trim.ToUpper) Then WorkBookExists = True Exit For End If Next End Function Any help would be greatly appreciated. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
HRESULT: 0x800A03EC exception when trying to hide a sheet. | Excel Programming | |||
Exception from HRESULT: 0x800A03EC | New Users to Excel | |||
Exception from HRESULT: 0x800AC472 | Excel Discussion (Misc queries) | |||
VSTO2005 - HResult Exception obtaining Range Object | Excel Programming | |||
Exception HResult: 0x8007FA08 (VB.net) | Excel Programming |