Home > database >  How to get the recordset data from Word VBA to excel sheet?
How to get the recordset data from Word VBA to excel sheet?

Time:09-20

I'm new to VBA, for part of a requirement I need to get the data from SQL table to Excel sheet using Word macro. I tried to

  1. Connect to SQL using ADODB connection and created & set an object for recordset
  2. I have created and set the necessary excel objects like Excel.Application, Excel.WorkBook and Excel.WorkSheet But I'm stuck with how to get the data from recordset into Excel sheet

CodePudding user response:

Here is a guide on the microsoft website: https://learn.microsoft.com/en-us/previous-versions/office/troubleshoot/office-developer/transfer-excel-data-from-ado-recordset

This part is probably the key bit you need (but you also may need the part before to process date values and other more complex data types:

' Transpose and Copy the array to the worksheet,
        ' starting in cell A2
        xlWs.Cells(2, 1).Resize(recCount, fldCount).Value = _
            TransposeDim(recArray)
  • Related