Can anyone tell me how to write files or output to an excel file with tabs etc.

Thanks,

GB4

Recommended Answers

All 3 Replies

Can anyone tell me how to write files or output to an excel file with tabs etc.

Thanks,

GB4

i've been able to write a comma-delimited file for use as an excel spreadsheet
quite easily. Even put a Total at the end of one column (only number column).

It does, however require the user to format the columns as to widths, etc. so
I would also be interested in any info about formatting the columns.

Thnnks for your reply. If you had a little more information or details on how to do this it would be much appreciated

Thanks

i've been able to write a comma-delimited file for use as an excel spreadsheet
quite easily. Even put a Total at the end of one column (only number column).

It does, however require the user to format the columns as to widths, etc. so
I would also be interested in any info about formatting the columns.

i've been able to write a comma-delimited file for use as an excel spreadsheet
quite easily. Even put a Total at the end of one column (only number column).

It does, however require the user to format the columns as to widths, etc. so
I would also be interested in any info about formatting the columns.

Hi There,

Here's a code snippet that writes the contents of an ADO recordset to a Excel file, you'll need to reference an Excel library in your project for it to work. Basically you need to learn about the Excel object model, try looking in your MSDN documentation.

'*******************************************************************************
' excelPrintRecordSet(Sub)
'
' PARAMETERS:
'
'
' RETURN VALUE:
'
'
' DESCRIPTION:
' Test function that will print out all the records from a recordset in Excel.
'*******************************************************************************
Public Sub excelPrintRecordSet(rstTmp As ADODB.Recordset)
  Dim appExcel As Excel.Application
  Dim wbkReport As Excel.Workbook
  Dim wksReport As Excel.Worksheet
  Dim intField As Integer, intRow As Integer
  
  Const PROCEDURE_NAME As String = "excelPrintRecordSet"

  On Error GoTo errorHandler

  Set appExcel = New Excel.Application
  appExcel.Visible = True
  Set wbkReport = appExcel.Workbooks.Add
  'wbkReportame = "Kilometer Report"
  Set wksReport = wbkReport.Worksheets(1)

  If rstTmp.EOF <> True Then
    rstTmp.MoveFirst
    intRow = 1
    Do
      For intField = 0 To rstTmp.Fields.Count - 1
        wksReport.Cells(intRow, intField + 1) = rstTmp.Fields(intField).Name & "=" & rstTmp.Fields(intField).Value
      Next intField
      rstTmp.MoveNext
      intRow = intRow + 1
    Loop Until rstTmp.EOF = True
  End If
  Exit Sub

errorHandler:
  frmErrorHandler.errorForm MODULE_NAME, PROCEDURE_NAME
  Err.Clear
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.