Link to home
Start Free TrialLog in
Avatar of M A
M AFlag for United States of America

asked on

Format excel when exporting from access

I have a code to highlight a filed. below is the code.
I would like to enable filter, freeze the first row and autofit  when exporting.
How to accomplish this?

Your help appreciated.


Private Sub Command48_Click()
Dim outputFileName As String
If Me.Dirty Then Me.Dirty = False
outputFileName = "Export_" & Format(Date, "dd-MM-yyyy") & ".xls"
DoCmd.OutputTo acOutputQuery, "Payment-Details", acFormatXLS, outputFileName
Call excel_format(outputFileName, "Payment-Details")
End Sub


Public Function excel_format(xls As String, sheet As String) As Long
Dim xlf As Object, wbk As Object, wks As Object
Dim i As Long, Lr As Long
Set xlf = CreateObject("Excel.Application")
Set wbk = xlf.Workbooks.Open(fGetSpecialFolderLocation(CSIDL_PERSONAL) & "\" & xls)
Set wks = wbk.Sheets(sheet)
Lr = wks.UsedRange.Rows.Count
For i = 2 To Lr
    If wks.cells(i, 35).value = "Low" Then wks.cells(i, 11).Interior.Color = vbGreen
    If wks.cells(i, 35).value = "Medium" Then wks.cells(i, 11).Interior.Color = vbYellow
    If wks.cells(i, 35).value = "High" Then wks.cells(i, 11).Interior.Color = vbRed
Next i
wbk.Save
xlf.Application.Visible = True ' If you like to show workbook
'wbk.close
'xlf.Quit ' quit excel
Set xlf = Nothing
Set wbk = Nothing
Set wks = Nothing
End function
SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of M A

ASKER

Where I have to apply this.

Within the function ?
if yes where? . I am not good in VB
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of M A

ASKER

Many thanks. It worked
Avatar of M A

ASKER

Many thanks. It worked
Avatar of M A

ASKER

Appreciate if you can send the code to bold the heading. Not urgent reply when you are free