Good morning Folks,
I'm looking for some help with my code. I have created the following function from reading various bits of information in this forum, but have got stuck on how to format the first row in an Excel Spreadsheet, and this is where I need help
I've found this example, but not sure how to adapt it to my needs and where in should fit within the above code:
Your assistance would be most appreciated.
John
I'm looking for some help with my code. I have created the following function from reading various bits of information in this forum, but have got stuck on how to format the first row in an Excel Spreadsheet, and this is where I need help
Code:
[FONT=Times New Roman][COLOR=blue]Function[/COLOR] ExportToExcel()[/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman][COLOR=blue]Dim[/COLOR] ExcelFile [COLOR=blue]As String[/COLOR] [/FONT]
[FONT=Times New Roman][COLOR=blue]Dim[/COLOR] ExcelWorksheet [COLOR=blue]As String[/COLOR] [/FONT]
[FONT=Times New Roman][COLOR=blue]Dim[/COLOR] FEDB [COLOR=blue]As String[/COLOR] [/FONT]
[FONT=Times New Roman][COLOR=blue]Dim[/COLOR] QueryName [COLOR=blue]As String[/COLOR] [/FONT]
[FONT=Times New Roman][COLOR=blue]Dim[/COLOR] objDB As Database [/FONT]
[FONT=Times New Roman][COLOR=blue]Dim[/COLOR] MyDate [/FONT]
[FONT=Times New Roman][COLOR=blue]Dim[/COLOR] MyWeekDay [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman]MyDate = [COLOR=blue]Date[/COLOR] [/FONT]
[FONT=Times New Roman]MyWeekDay = Weekday(MyDate) 'MyWeekDay represents the current day in the week[/FONT]
[FONT=Times New Roman] [/FONT]
[COLOR=green][FONT=Times New Roman]'If today is Friday then[/FONT][/COLOR]
[FONT=Times New Roman][COLOR=blue]If[/COLOR] MyWeekDay = 4 [COLOR=blue]Then[/COLOR][/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] ExcelFile = "G:\Biasi\WC" & "_" & Format(Date - 4, "ddmmyy") & ".xls" [/FONT]
[FONT=Times New Roman] ExcelWorksheet = "WC " & Format(Date - 4, "ddmmyy") [/FONT]
[FONT=Times New Roman] FEDB = "H:\John Lee\eFlowStatsFrontEnd.mdb" [/FONT]
[FONT=Times New Roman] QueryName = "qryExportToExceltblBiasi" [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] [COLOR=blue]Set[/COLOR] objDB = OpenDatabase(FEDB) [/FONT]
[FONT=Times New Roman] [/FONT]
[COLOR=green][FONT=Times New Roman] 'Excute the creation of the Excel file[/FONT][/COLOR]
[FONT=Times New Roman] objDB.Execute "Select*Into[Excel 8.0;Database=" & ExcelFile & "].[" & ExcelWorksheet & "] From " & "[" & QueryName & "]"[/FONT]
[FONT=Times New Roman] objDB.Close 'Close the eFlowStatsFrontEnd database[/FONT]
[FONT=Times New Roman] [COLOR=blue]Set[/COLOR] objDB = [COLOR=blue]Nothing[/COLOR] [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] DoCmd.OpenQuery "qrpApptblBiasiProcessHistoryToLongTerm", acNormal, acEdit[/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] DoCmd.OpenQuery "qryDeltblBiasiProcessHistory", acNormal, acEdit[/FONT]
[FONT=Times New Roman] [/FONT]
[COLOR=blue][FONT=Times New Roman]End If[/FONT][/COLOR]
[FONT=Times New Roman] [/FONT]
[COLOR=blue][FONT=Times New Roman]End Function[/FONT][/COLOR]
I've found this example, but not sure how to adapt it to my needs and where in should fit within the above code:
Code:
ObjXL.WorkbooksOpen ()
with ObjXL
.Worksheets(worksheetname).Rows("1:1").Font.Bold = True
.Columns("A:Z").Autofit
.Save
.Workbooks.Close
End With
Your assistance would be most appreciated.
John