I am using some code I got from another source to output from Access to Excel. I want to create an Excel worksheet with specific formatting at the top of the page and then place the data following that. The following code works - sort of. It does place the text exactly where I want it, but it doesn't format it. I want to put in some merged cells and some borders. Can someone tell me why it is not formatting the text? If I run a macro in Excel with the same general code, it works - formats with the borders and merges the cells.
MrsBean
Code:
Private Sub cmdMamasItems_Click()
Dim response As VbMsgBoxResult
response = _
MsgBox("This action may take several minutes." & _
vbCrLf & "Do you wish to continue...?", _
vbQuestion + vbOKCancel)
If response = vbOK Then
DoCmd.Hourglass True
Dim rs As DAO.Recordset
Dim xlApp As Excel.Application
Dim intCol As Integer
Dim strFileName As String
Dim strSQL As String
Set xlApp = New Excel.Application
xlApp.Workbooks.Add
Set rs = CurrentDb.OpenRecordset("qry_MAMAS_ITEMS")
'add title to this section
xlApp.Cells(2, 3).Value = "Deluxe Pizza"
xlApp.Range("c2:i2").Select
Selection.Font.Bold = True
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
xlApp.Cells(2, 10).Value = "$5 Pizza"
xlApp.Range("j2:k2").Select
Selection.Font.Bold = True
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
xlApp.Cells(2, 14).Value = "Slices"
xlApp.Range("n2:o2").Select
Selection.Font.Bold = True
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
xlApp.Cells(2, 16).Value = "Drinks"
xlApp.Range("p2:s2").Select
Selection.Font.Bold = True
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
xlApp.Cells(2, 20).Value = "Extras"
xlApp.Range("t2:y2").Select
Selection.Font.Bold = True
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
xlApp.ActiveWorkbook.SaveAs FileName:="mamasItems.xls"
Shell "C:\Program Files\Microsoft Office\OFFICE11\excel.exe"
& " " & "mamasItems.xls", vbMaximizedFocus
xlApp.Quit
Set xlApp = Nothing
Set rs = Nothing
End If
ExitHere:
DoCmd.Hourglass False
Exit Sub
'HandleErrors:
'MsgBox Err.Description
'Resume ExitHere
End Sub
MrsBean