BamaColtsFan
Registered User.
- Local time
- Today, 10:01
- Joined
- Nov 8, 2006
- Messages
- 91
Greetings!
I am using a VBA module to first export then format a query result from Access to Excel. Before I started trying to format the results, everything worked perfectly. I am able to send my results to Excel without any problems. Now, I'm trying to format my results a little but for some reason, there are two instances of Excel opening when I execute the code. I think it has something to do with how I'm calling the Excel application but I'm not sure. A shortened version of the code is below (only 1 sheet as opposed to the many that I actually export). My question is "Why are there two copies opening?"
Any advice would be deeply appreciated!
I am using a VBA module to first export then format a query result from Access to Excel. Before I started trying to format the results, everything worked perfectly. I am able to send my results to Excel without any problems. Now, I'm trying to format my results a little but for some reason, there are two instances of Excel opening when I execute the code. I think it has something to do with how I'm calling the Excel application but I'm not sure. A shortened version of the code is below (only 1 sheet as opposed to the many that I actually export). My question is "Why are there two copies opening?"
Any advice would be deeply appreciated!
Code:
Public Function CopyToWorkbook()
' This is the test function to format the output in Excel
Dim db As DAO.Database
Dim newPath As DAO.Recordset
Dim strPath As String
Set db = CurrentDb()
Dim ApXL As Object
Dim xlWBk As Object
Dim xlWSh As Object
Set newPath = db.OpenRecordset("Set_Path")
Set ApXL = CreateObject("Excel.Application")
strPath = newPath!Out_Path & "CombinedTimecards_Crosstab.xlsx"
Set xlWBk = ApXL.Workbooks.Open(strPath)
ApXL.Visible = True
DoCmd.TransferSpreadsheet acExport, 8, "qryFinalCompSum", strPath, True, "Compliance Summary"
Set xlWSh = xlWBk.Worksheets("Compliance_Summary")
xlWSh.Columns("A:E").Select
With ApXL.Selection.Font
.Name = "Arial"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
End With
xlWSh.Range("A1:E1").Select
With ApXL.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 16628595
.TintAndShade = 0
.PatternTintAndShade = 0
End With
ApXL.Selection.Font.Bold = True
ApXL.ActiveSheet.Cells.Select
ApXL.ActiveSheet.Cells.EntireColumn.AutoFit
xlWSh.Range("A1").Select
xlWSh.Columns("B:B").Select
ApXL.Selection.Style = "Percent"
ApXL.Selection.NumberFormat = "0.0%"
xlWSh.Range("A1").Select
Exit Function
End Function