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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.