Hey all, having a bit of a hiccup up with my table export function from my dBase. It's set to export to .xls, but I would really like it to be .xlsx since we are running Office 365/2016. However, when I change the output parameters to .xlsx, I get an error in my formatExcellSS code.
Any thoughts on why this is happening would be great.
Here is my cmdExport code
Here is the FormatExcelSS coding, and it errors our on the Bold/Red line.
Any thoughts on why this is happening would be great.
Here is my cmdExport code
Code:
Private Sub cmdExport_Click() Dim arrCurrentFormInfo
Dim strCurrentForm
Dim strCaption
Dim strOutputFileName
Dim strRecordSource
Dim strOutputFile
Dim objShell
Set objShell = VBA.CreateObject("wscript.shell")
arrCurrentFormInfo = Split(txtCurrentForm.Value, ":")
If UBound(arrCurrentFormInfo) = 1 Then
strCurrentForm = Replace(arrCurrentFormInfo(0), "form.", "")
strOutputFileName = arrCurrentFormInfo(1)
Else
strCurrentForm = Replace(txtCurrentForm.Value, "form.", "")
strOutputFileName = strCurrentForm
End If
strRecordSource = Me!NavigationSubform.Form.RecordSource
strOutputFile = Application.CurrentProject.Path & "\" & strOutputFileName & ".xlsx"
'DoCmd.OutputTo acOutputForm, frmCurrentForm, acFormatXLSX, Application.CurrentProject.Path & "\" & txtOutputFileName & ".xlsx", -1
If Left(strRecordSource, 3) = "tbl" Then
DoCmd.OutputTo acOutputTable, strRecordSource, acFormatXLS, strOutputFile
Else
DoCmd.OutputTo acOutputQuery, strRecordSource, acFormatXLS, strOutputFile
End If
Call FormatExcelSS(strOutputFile, "B1")
objShell.Run "Excel.exe" & " " & Chr(34) & strOutputFile & Chr(34), , True
End Sub
Here is the FormatExcelSS coding, and it errors our on the Bold/Red line.
Code:
Sub FormatExcelSS(sXLFile, strSortRange) Dim xlApp, xlWB
Dim objRange, objRange2
Set xlApp = VBA.CreateObject("excel.application")
[COLOR=#ff0000][B] Set xlWB = xlApp.Workbooks.Open(sXLFile)[/B][/COLOR]
With xlWB 'open file With .ActiveSheet
.Rows(1).Font.Bold = True '1. Bold the headers (always in row 1)
.Rows(1).Interior.ColorIndex = 15
.AutoFilterMode = False 'turn off any existing autofilter just in Case
Set objRange = .UsedRange
objRange.Columns.ColumnWidth = 100
.Rows.AutoFit
.Rows(1).AutoFilter '2. Turn on AutoFilter for all coloms
.Columns.AutoFit '3. Set Column width to AutoFit Selection
'4. Set a freeze under column 1 so that the header is always present at the top
.Range("A2").Select
xlApp.ActiveWindow.FreezePanes = True
'Sort on specified column
Const xlAscending = 1
Const xlYes = 1
Set objRange2 = .Range(strSortRange)
objRange.Sort objRange2, xlAscending, , , , , , xlYes
End With
.Worksheets(1).Activate
.Close True 'save and close
End With
xlApp.Quit
Set xlApp = Nothing
End Sub