I got the next code in form application using vb in visual studio 2019, when i execute the sub cmd_data_Click i got the next error
System.Runtime.InteropServices.COMException: 'Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).'
How can i solved?
Imports System.Data.OleDb
Imports System.IO
Imports Excel = Microsoft.Office.Interop.Excel
Public Class frm_main
Private Sub cmd_nuevo_Click(sender As Object, e As EventArgs) Handles cmd_nuevo.Click
frm_newPt1.Show()
End Sub
Private Sub cmd_activos_Click(sender As Object, e As EventArgs) Handles cmd_activos.Click
frm_activos.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles cmd_seguimientoQRQC.Click
frm_selectionQRQC.Show()
End Sub
Private Sub cmd_data_Click(sender As Object, e As EventArgs) Handles cmd_data.Click
Dim APP As New Excel.Application
Dim worksheet As Excel.Worksheet
Dim workbook As Excel.Workbook
Dim cadena As New OleDbConnection
Dim oda As New OleDbDataAdapter
Dim ods As New DataSet
Dim consulta As String
Dim registro As Integer
If Dir("C:\QRQC\DataQRQC.xlsx", vbArchive) <> "" Then
Kill("C:\Scripts\DataQRQC.xlsx")
End If
cadena.ConnectionString = conexion
My.Computer.FileSystem.CopyFile("C:\Users\2460473\Desktop\QRQC\DataQRQC.xlsx", "C:\QRQC\DataQRQC.xlsx")
workbook = APP.Workbooks.Open("C:\QRQC\DataQRQC.xlsx")
worksheet = workbook.Worksheets("QRQC")
consulta = "Select *From QRQC"
oda = New OleDbDataAdapter(consulta, cadena)
ods.Tables.Add("QRQC")
oda.Fill(ods.Tables("QRQC"))
registro = ods.Tables("QRQC").Rows.Count
For i = 0 To registro - 1 Step 1
worksheet.Range("A" & (i + 2)).Value = ods.Tables("QRQC").Rows(i).Item("ID_QRQC")
Next
workbook.Save()
APP.Quit()
ods.Tables.Clear()
MsgBox("El documento fue generado en la siguiente ruta C:\QRQC\DataQRQC.xlsx", vbInformation, "Aviso")
End Sub
End Class
User contributions licensed under CC BY-SA 3.0