esmatullaharifi
New Member
- Joined
- Apr 17, 2015
- Messages
- 12
Hello Dears.
I used this vba code to export the query from access to excel but it exports in excel97 format how to change this to get compatible with access 2013 and output must be excel 2013.
I used this vba code to export the query from access to excel but it exports in excel97 format how to change this to get compatible with access 2013 and output must be excel 2013.
Code:
Option Explicit
Const fPath = "C:\My Documents\" 'adjust to suit
Const fname = "Formatter File.xls" ' Code file
Const fName2 = "Exported Data.xls" ' Data file to overwrite
Function OpenExcel()
On Error GoTo ErrorHandler
Dim appExcel As Excel.Application
Dim bks As Excel.Workbooks
Dim sht As Excel.worksheet
Dim strSheet As String
Dim MyFile As String
MyFile = fPath & fname2 'Point to the Data file
DoCmd.OutputTo acQuery, "qryCourseScheduleRpt", "MicrosoftExcel(*.xls)", _
MyFile, True, ""
'Open the Code file and run the processing macro
MyFile = fPath & fName ' point to the Code file
Set appExcel = GetObject(, "Excel.Application")
appExcel.Workbooks.Open (MyFile)
Set sht = appExcel.ActiveWorkbook.Sheets(1)
sht.Activate
'appExcel.Application.Visible = True
With appExcel
.Run "OpenAndProcess" 'Change to suit name of Excel routine
End With
ErrorHandlerExit:
Exit Function
ErrorHandler:
If Err = 429 Then
'Excel is not running; open Excel with CreateObject
Set appExcel = CreateObject("Excel.Application")
Resume Next
Else
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End If
End Function