Hello,
I have a form where there is a button which export my query "qryReportsBureauT" to excel asking user to save the excel file first than it will open automatically.
My problem is that the export data in excel file doesn't look like in good format. What I want that the format should be pre-defined. ie. Header should be bold and colored. Other data font type, size and autofit should be coded into VBA so it could look better and save user time to format it again and again.
Here is my code which work fine:
Private Sub Command141_Click()
On Error GoTo Err_btnlogin_Click
Dim stDocName As String
stDocName = "qryReportsBureauT" 'my query'
'DoCmd.OpenQuery stDocName, acNormal, acEdit
Const QueryName As String = "qryReportsBureauT"
Const SheetType As Byte = acSpreadsheetTypeExcel9
MsgBox "Save your report...Wait for few seconds...Report will open automatically !!!"
DoCmd.OutputTo ObjectType:=acOutputQuery, ObjectName:="qryReportsBureauT", _
OutputFormat:=acFormatXLSX, AutoStart:=True
Exit_btnlogin_Click:
Exit Sub
Err_btnlogin_Click:
MsgBox Err.Description
Resume Exit_btnlogin_Click
End Sub
I would be thankful for your help !!!
Santosh
I have a form where there is a button which export my query "qryReportsBureauT" to excel asking user to save the excel file first than it will open automatically.
My problem is that the export data in excel file doesn't look like in good format. What I want that the format should be pre-defined. ie. Header should be bold and colored. Other data font type, size and autofit should be coded into VBA so it could look better and save user time to format it again and again.
Here is my code which work fine:
Private Sub Command141_Click()
On Error GoTo Err_btnlogin_Click
Dim stDocName As String
stDocName = "qryReportsBureauT" 'my query'
'DoCmd.OpenQuery stDocName, acNormal, acEdit
Const QueryName As String = "qryReportsBureauT"
Const SheetType As Byte = acSpreadsheetTypeExcel9
MsgBox "Save your report...Wait for few seconds...Report will open automatically !!!"
DoCmd.OutputTo ObjectType:=acOutputQuery, ObjectName:="qryReportsBureauT", _
OutputFormat:=acFormatXLSX, AutoStart:=True
Exit_btnlogin_Click:
Exit Sub
Err_btnlogin_Click:
MsgBox Err.Description
Resume Exit_btnlogin_Click
End Sub
I would be thankful for your help !!!
Santosh