Claro, lo que pasa es que en otros equipos donde corro el programa no me presenta ningun error.
pero adjunto code
lic Sub generador(ByVal vw As String, ByVal archivos As String, ByVal pathfile As String)
Dim fecha As Date = Today.Date
Dim exapp As New Microsoft.Office.Interop.Excel.Application
Dim exlibro As Microsoft.Office.Interop.Excel.Workbook
Dim exHoja As Microsoft.Office.Interop.Excel.Worksheet
Dim f1 As String
Dim dr As DataRow, ary() As Object
f1 = fecha.ToString("ddMMyyyy")
cnn = New SqlConnection(config.ConnectionString)
cnn.Open()
'Dim sql As String = "select [Cg_Emp_Codigo_Empresa],[Ps_Ccl_Clasificacion],[Ps_Cvc_Valor_Clasificacion],[Ps_Cvc_Descripcion],[Ps_Cvc_Account_Prod_Code],[Cb_Cct_Codigo_Cuenta],[Ps_Cvc_Porc_Impuesto],[Ps_Cvc_MarkUP],[Ps_Cvc_Precios_Modificables],[Ps_Cvc_Afecta_Af],[Ps_Cvc_Incluido_Garantia],[Ps_Cvc_ExcepcionVenta],[Ps_Cpp_Warning_DiasFinS] from [XLAR].[dbo].[Ps_Cat_Valor_Clasificacion]"
Dim sql As String = "select * From " & vw & ""
Me.Cursor = Cursors.WaitCursor
cmd = New SqlCommand(sql, cnn)
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, cnn)
'Dim ds As New DataSet
Dim dt As New DataTable("TABLA")
da.Fill(dt)
'da.Fill(ds)
GC.Collect()
Try
If My.Computer.FileSystem.FileExists(archivos) Then
My.Computer.FileSystem.DeleteFile(archivos)
End If
Me.Cursor = Cursors.WaitCursor
Dim oldCI As System.Globalization.CultureInfo = _
System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = _
New System.Globalization.CultureInfo("en-US")
'se añade el libro al programa, y la hoja al libro
Dim ncol As Integer = dt.Columns.Count 'ColumnCount
Dim nrow As Integer = dt.Rows.Count
Dim intI As Integer = 1
'Dim dc As DataColumn
Dim array(nrow, ncol) As Object
If archivoBase = "si" Or archivoBase = "Si" Or archivoBase = "SI" Or archivoBase = "yes" Or archivoBase = "Yes" Or archivoBase = "YES" Then
exlibro = exapp.Workbooks.Open(pathfile)
exHoja = exlibro.Worksheets(1)
ElseIf archivoBase = "no" Or archivoBase = "No" Or archivoBase = "NO" Then
exlibro = exapp.Workbooks.Add
exHoja = exlibro.Worksheets(1)
For col = 0 To dt.Columns.Count - 1
exHoja.Cells(1, intI).value = dt.Columns(col).ColumnName
exHoja.Cells(1, intI).EntireRow.Font.Bold = True
intI += 1
Next
End If
'Cuantas columnas y filas
' Se recoge todas la filas, y por cada fila todas las columnas y se va escribiendo.
'Exportar por rango + eficiente
For fila As Integer = 0 To nrow - 1
For col As Integer = 0 To ncol - 1
dr = dt.Rows.Item(fila)
ary = dr.ItemArray
array(fila, col) = ary(col).ToString
Next
Next
exHoja.Range("A2").Resize(nrow, ncol).Value = array
'exporta por celda - eficiente para muchos registros.
'For fila As Integer = 0 To nrow - 1
' For col As Integer = 0 To ncol - 1
' dr = dt.Rows.Item(fila)
' ary = dr.ItemArray
'exHoja.Cells.Item(fila + 2, col + 1) = ElGrid.Rows(fila).Cells(col).Value
'exHoja.Cells.Item(fila + 2, col + 1) = ary(col).ToString
'ProgressBar1.Value = fila
' Next
'Next
exapp.Application.Visible = True
'exapp.ActiveWindow.Visible = False
exHoja = exlibro.Worksheets(2)
exapp.ActiveWorkbook.RefreshAll()
'exHoja = exlibro.Worksheets(1)
'exapp.ActiveWorkbook.RejectAllChanges(exHoja)
exapp.ActiveWorkbook.SaveAs(archivos)
exapp.Workbooks(filename).Close()
exapp.Quit()
exHoja = Nothing
exlibro = Nothing
exapp = Nothing
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI
Dim pro() As Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")
For Each i As Process In pro
i.Kill()
Next
'comprime(ZIPDOC & DateTime.Now.ToString("yyMMdd") & ".zip")
Me.Cursor = Cursors.Default
Catch ex As Exception
Dim msg As String = "Error(on Sub GENERADOR): " & ex.Message.ToString & Now
sendmailFijo(msg)
MsgBox(ex.Message, MsgBoxStyle.Critical, " Failed export to Excel")
Dim pro() As Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")
For Each i As Process In pro
i.Kill()
Next
Me.Cursor = Cursors.Default
Return
End Try
'Return
End Sub
Saludos