Hi. I am trying to export two queries from Access 2007 into Excel. I would like the queries to be on separate sheets within the workbook. I have this working the way I would like. In both queries I have a Boolean field. If the Boolean is Yes than I would like to highlight the Excel row red. Is this possible? The code I have for the export is:
Many thanks.
Code:
Dim strExcelFile As String
Dim strWorksheetActive As String
Dim strWorksheetCancel As String
Dim strDB As String
Dim strTableActive As String
Dim strTableCancel As String
Dim objDB As Database
Dim strUser As String
Dim ApXl As Object
Set ApXl = CreateObject("Excel.Application")
strUser = fOSUserName()
'Change Based on your needs, or use
'as parameters to the sub
strExcelFile = "U:\" & strUser & "\DealerContacts.xls"
strWorksheetActive = "ActiveDealers"
strWorksheetCancel = "CanceledDealers"
strDB = "U:\Contacts DB"
strTableActive = "qryExcelExportActive"
strTableCancel = "qryExcelExportCancel"
Set objDB = CurrentDb
'If excel file already exists, you can delete it here
If Dir(strExcelFile) <> "" Then Kill strExcelFile
objDB.Execute _
"SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
"].[" & strWorksheetActive & "] FROM " & "[" & strTableActive & "]"
objDB.Execute _
"SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
"].[" & strWorksheetCancel & "] FROM " & "[" & strTableCancel & "]"
MsgBox "Thank you. The files has been saved on the U drive under U:\DealerContacts", vbInformation, "Export Saved"
objDB.Close
Set objDB = Nothing
End Sub
Many thanks.