How to assign a value to a cell of excel without automation error? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to assign a value to a cell of excel without automation error?

I have the code below. When it try to execute the line that changes the value of the cell, it occurs an automation error. If I try to look at value of cell through immediate window. I dont know why.

Dim nContaColuna As Integer
Dim xPlanilha As Excel.Application
Dim xPasta As Excel.Workbook
Dim xGrade As Excel.Worksheet
Dim xPastaClientes As Excel.Worksheet
Dim rsRegistro As DAO.Recordset

Set rsRegistro = dbSGO.OpenRecordset(sSql, dbOpenSnapshot)
Set xPlanilha = CreateObject("Excel.Application")
Set xPasta = xPlanilha.Workbooks.Add
Set xGrade = xPasta.Sheets("Plan1")
xGrade.Name = sNomePasta
Set xPastaClientes = xPasta.Sheets(sNomePasta)

If Not (rsRegistro.BOF And rsRegistro.EOF) Then
For nContaColuna = 0 To rsRegistro.Fields.Count - 1
xPastaClientes.Cells(1, nContaColuna + 1).Value = rsRegistro.Fields(nContaColuna).Name
Next
xPastaClientes.Range("A2").CopyFromRecordset rsRegistro
End If


Sign In or Register to comment.