VBA to Export Access Select Queries to Excel Files- Error

aravindhan_31

Well-known Member
Joined
Apr 11, 2006
Messages
672
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi, I wanted to export the result of the query to an excel & I have the below vba code which exports as an excel file, but I am not able to open the excel file it says file extension not valid
code taken from http://www.mrexcel.com/forum/micros...export-access-select-queries-excel-files.html
Code:
Private Sub ExportExcel()
 
    Dim i As Integer
    Dim myQueryName As String
    Dim myExportFileName As String
        myQueryName = "Result1"
        myExportFileName = "C:\Users\aravindhan.jayaraman\Desktop\ACAT" & myQueryName & ".xlsb"
        DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, myQueryName, myExportFileName, True
   
 End Sub

can someone helpe me pelase
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
As far as I recall acSpreadsheetTypeExcel9 is for Excel 2000 files, ie files with the xls extension.

Try using acSpreasheetTypeExcel12 (or acSpreadsheetTypeExcel12Xml) and change xlsb to xlsx.
 
Upvote 0
so, if excel 2016 what number should be changed? can u help me with that please?
 
Upvote 0
Like I said, change acSpreadsheetTypeExcel9 to acSpreasheetTypeExcel12 or acSpreasheetTypeExcel12Xml and change the file extension from 'xlsb' to 'xlsx'.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top