Hey guys,
I am trying to get my program to create an excel file and populate it with data from my program. I have attached the code I am using.
If excel is not open I receive an error that says "Cannot create ActiveX componet"
if excel is open I receive this error " "could not be found. Check the spelling of the file name, and verify that the file location is correct"
I believe this error is coming up becuase the dialog box has not yet been created and the filename retrieved from the user.
I do not want to have to have excel open in order to create an excel file with some data in it. Is there another way to do this? Is it possible to start excel automaicly and hide it from the user so they don't notice it being open?
Code:Dim intCount As Integer = 0 Dim strMachine As String Dim strTemp As String Dim strDescription As String Dim strFinal As String Dim bolTestcb As Boolean Dim hashSave As New Hashtable Dim intExcelCount As Integer = 0 Dim intX As Integer = 0 Dim byteCol As Byte = 0 Dim bolExcel As Boolean = False Dim intExcelRow As Integer = 0 Dim oWB As Excel.Workbook Dim bOpen As Boolean If rbExcel.Checked = True Then bolExcel = True Try oApp = GetObject(, "Excel.Application") If oApp Is Nothing Then oApp = New Excel.Application For Each oWB In oApp.Workbooks If oWB.Name = dlgSave.FileName Then bOpen = True Exit For Else bOpen = False End If Next If bOpen = True Then 'Already open oWB = oApp.Workbooks(dlgSave.FileName) Else 'Open your wb oWB = oApp.Workbooks.Open(dlgSave.FileName) End If oApp.Visible = True Catch exp As Exception MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End If




Reply With Quote