Error Object Variable or Workbooks variable no set - Cuando instalo Service Pack 4
Tengo una aplicación en la exporto de una DataGrid a Excel me funciona correctamente, cuando instalo el Service Pack 4 de Windows 2000 , cuando hago el proceso me tira el siguiente error Error Object Variable or Workbooks variable no set
El Codigo es el siguiente
' Declare object variables for Microsoft Excel,
' application workbook, and worksheet objects.
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim StartRow As Integer
Dim EndRow As Integer
Dim Repetir, li_ret As Integer
'Set objExcel = CreateObject("Excel.Application")
On Error GoTo ErrorHandler
ExportarAExcel = True
' Assign object references to the variables. Use
' Add methods to create new workbook and worksheet
' objects.
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
'Set xlSheet = xlBook.Worksheets.Add
Set xlSheet = xlBook.Worksheets(1)
If novedadgrid.Row < novedadgrid.RowSel Then
StartRow = novedadgrid.Row
EndRow = novedadgrid.RowSel
Else
StartRow = novedadgrid.RowSel
EndRow = novedadgrid.Row
End If
novedadgrid.Row = StartRow
novedadgrid.RowSel = EndRow
' Assign the values entered in the text boxes to
' Microsoft Excel cells.
xlSheet.Cells(1, 1).Value = "Hora"
xlSheet.Cells(1, 2).Value = "Fecha"
xlSheet.Cells(1, 3).Value = "Sucursal"
xlSheet.Cells(1, 4).Value = "Novedad"
ProgressBar1.Min = Repetir
ProgressBar1.Max = EndRow - StartRow + 2
ProgressBar1.Visible = True
For Repetir = 2 To EndRow - StartRow + 2
novedadgrid.Col = 0
xlSheet.Cells(Repetir, 1).Value = novedadgrid.Text
novedadgrid.Col = 1
xlSheet.Cells(Repetir, 2).Value = novedadgrid.Text
novedadgrid.Col = 2
xlSheet.Cells(Repetir, 3).Value = novedadgrid.Text
novedadgrid.Col = 3
xlSheet.Cells(Repetir, 4).Value = novedadgrid.Text
If novedadgrid.Row < novedadgrid.Rows - 1 Then _
novedadgrid.Row = novedadgrid.Row + 1
' Use the Formula method to add the values in
' Microsoft Excel.
'xlSheet.Cells(3, 1).Formula = "=R1C1 + R2C1"
'Text3.Text = xlSheet.Cells(3, 1)
ProgressBar1.Value = Repetir
Next
' Save the Worksheet
xlSheet.SaveAs "a:" & NombreArchivo & ".xls"
ProgressBar1.Visible = False
'xlSheet.SaveAs NombreArchivo & ".xls"
' Close the Workbook
xlBook.Close (0)
' Close Microsoft Excel with the Quit method.
xlApp.Quit
' Release the objects.
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
Exit Function
El Codigo es el siguiente
' Declare object variables for Microsoft Excel,
' application workbook, and worksheet objects.
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim StartRow As Integer
Dim EndRow As Integer
Dim Repetir, li_ret As Integer
'Set objExcel = CreateObject("Excel.Application")
On Error GoTo ErrorHandler
ExportarAExcel = True
' Assign object references to the variables. Use
' Add methods to create new workbook and worksheet
' objects.
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
'Set xlSheet = xlBook.Worksheets.Add
Set xlSheet = xlBook.Worksheets(1)
If novedadgrid.Row < novedadgrid.RowSel Then
StartRow = novedadgrid.Row
EndRow = novedadgrid.RowSel
Else
StartRow = novedadgrid.RowSel
EndRow = novedadgrid.Row
End If
novedadgrid.Row = StartRow
novedadgrid.RowSel = EndRow
' Assign the values entered in the text boxes to
' Microsoft Excel cells.
xlSheet.Cells(1, 1).Value = "Hora"
xlSheet.Cells(1, 2).Value = "Fecha"
xlSheet.Cells(1, 3).Value = "Sucursal"
xlSheet.Cells(1, 4).Value = "Novedad"
ProgressBar1.Min = Repetir
ProgressBar1.Max = EndRow - StartRow + 2
ProgressBar1.Visible = True
For Repetir = 2 To EndRow - StartRow + 2
novedadgrid.Col = 0
xlSheet.Cells(Repetir, 1).Value = novedadgrid.Text
novedadgrid.Col = 1
xlSheet.Cells(Repetir, 2).Value = novedadgrid.Text
novedadgrid.Col = 2
xlSheet.Cells(Repetir, 3).Value = novedadgrid.Text
novedadgrid.Col = 3
xlSheet.Cells(Repetir, 4).Value = novedadgrid.Text
If novedadgrid.Row < novedadgrid.Rows - 1 Then _
novedadgrid.Row = novedadgrid.Row + 1
' Use the Formula method to add the values in
' Microsoft Excel.
'xlSheet.Cells(3, 1).Formula = "=R1C1 + R2C1"
'Text3.Text = xlSheet.Cells(3, 1)
ProgressBar1.Value = Repetir
Next
' Save the Worksheet
xlSheet.SaveAs "a:" & NombreArchivo & ".xls"
ProgressBar1.Visible = False
'xlSheet.SaveAs NombreArchivo & ".xls"
' Close the Workbook
xlBook.Close (0)
' Close Microsoft Excel with the Quit method.
xlApp.Quit
' Release the objects.
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
Exit Function
