Export Queries to Excel Template

I

If

Hello,

I have the code below which opens a template Excel.

My Question :
After the opening of this template, I would like to use the
DoCmd.TransferSpreadsheet function.

I must use this function which prevents me errors.
I would thus like not to use a connection DAO.

Already thank you for your ideas and your assistance.

Yves



'----------------------------------------------------------------
Sub ExportQueriesToExcel()

Dim strTemplateDir As String
Dim strWorksheet As String
Dim strWorksheetPath As String
Dim strTemplatePath As String
Dim xlapp As Excel.Application
Dim xlBook As Excel.Workbooks
Dim xlSheet As Excel.Worksheet

Set xlapp = GetObject(, "Excel.Application")
strTemplatePath = xlapp.Application.TemplatesPath
strWorksheet = "Template.xlt"
strWorksheetPath = strTemplatePath & strWorksheet

Set xlBook = xlapp.Workbooks

'Open the workbook
xlBook.Add strWorksheetPath

End Sub
'----------------------------------------------------------------
 
V

Van T. Dinh

I don't think you can use TransferSpreadsheet in this case.

Check Excel VB Help on the CopyFromRecordset Method instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top