I am trying to format an Excel spreadsheet from within Access VBA. I have written a fair amount of VBA code in Access but its the first time I've tried to manipulate another application. I'm using Access 97.
When I try to execute the code below it highlights xlCenter and tells me Compile error: variable not defined.
Also, the close command prompts for user to save, "Yes, No, Cancel". How can I bypass this and automatically save the file.
Thanks,
JW
When I try to execute the code below it highlights xlCenter and tells me Compile error: variable not defined.
Also, the close command prompts for user to save, "Yes, No, Cancel". How can I bypass this and automatically save the file.
Thanks,
JW
Code:
Dim oXL As Object 'Excel.Application
Dim oWb As Object 'Excel.Workbook
Dim oSh As Object 'Excel.Worksheet
Dim X As Integer
Dim currentRow, currentColumn, currentQuarter As String, categoryChanged As Boolean, currentCategoryID As Integer
Set oXL = CreateObject("Excel.Application")
Set oWb = oXL.Workbooks.Open("M:\matlmgmt\lineitm3Comm.xls")
Set oSh = oWb.Sheets("lineitm3Comm")
currentRow = 1
currentColumn = 1
With oWb.ActiveSheet
.Cells(currentRow, currentColumn).Value = "BUDGET"
.Cells(currentRow, currentColumn).Font.Bold = True
.Cells(currentRow, currentColumn).Font.Name = "Arial"
.Cells(currentRow, currentColumn).Font.Size = 11
.Cells(currentRow, currentColumn).HorizontalAlignment = xlCenter
End With
oWb.Close
'Do not forget to clean up properly:
Set oSh = Nothing
Set oWb = Nothing
Set oXL = Nothing
End Function