With appExcel.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With appExcel.Selection
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
Save and close the filled-in worksheet, using a workbook save name with the date range:
strSheetName = “Northwind Orders as of “ _
& Format(Date, “d-mmm-yyyy”)
Debug.Print “Sheet name: “ & strSheetName
Write the title with the date range to the worksheet:
wks.Range(“A1”).Value = strSheetName
strSaveName = strDBPath & strSheetName & “.xlsx”
Debug.Print “Time sheet save name: “ & strSaveName
ChDir strDBPath
On Error Resume Next
If there already is a saved worksheet with this name, delete it:
Kill strSaveName
On Error GoTo ErrorHandler
wkb.SaveAs FileName:=strSaveName, _
FileFormat:=xlWorkbookDefault
wkb.Close
rst.Close
Put up a success message with the name and path of the new worksheet:
strTitle = “Workbook created”
strPrompt = strSheetName & vbCrLf & “created in “ _
& strDBPath
MsgBox strPrompt, vbOKOnly + vbInformation, strTitle
ErrorHandlerExit:
Exit Sub
ErrorHandler:
‘Excel is not running; open Excel with CreateObject
Part I The Office Components and What They Do Best