我收到错误
Object type argument for the action or method is blank or invalid
真的不明白为什么我使用的代码在另一个数据库中工作。这是代码:
'Print the report
Private Sub printReport()
Dim myReport As String
Dim oXL As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Object
DoCmd.SetWarnings False
myReport = "\Desktop" & "Report_" & (Format(Now(), "yyyymmdd")) & ".xls"
If GetVersion = "11.0" Then
DoCmd.OutputTo acOutputQuery, qryTest, acSpreadsheetTypeExcel9, myReport
ElseIf GetVersion = "12.0" Then
DoCmd.OutputTo acOutputQuery, qryTest, acSpreadsheetTypeExcel12, myReport
Else
DoCmd.OutputTo acOutputQuery, qryTest, "Excel 97 - Excel 2003 Workbook (*.xls)", myReport
End If
Set oXL = New Excel.Application
oXL.Visible = True
Set oBook = oXL.Workbooks.Open(myReport )
Set oSheet = oXL.ActiveSheet
With oBook.ActiveSheet.PageSetup
.CenterHeader = "Hep C New Patient Report " & (Format(Now(), "m/d/yyyy"))
.CenterFooter = "&P"
.PrintTitleRows = "$1:$1"
.PrintTitleColumns = "$A:$A"
.Orientation = 2 '1 = Portrait, 2 = Landscape
.LeftMargin = 18 '72 = 1 inch
.RightMargin = 18
.TopMargin = 54
.BottomMargin = 54
.PrintGridlines = True
.PaperSize = 1 '5 = Legal, 1 = Letter
.ORDER = 2 '2 = Over then down, 1 = Down then over
End With
oSheet.Cells.Select
oSheet.Cells.EntireColumn.AutoFit
oBook.Save
oXL.Visible = False
If (MsgBox("Is it OK to close the report and return to CPE Application?", vbYesNo)) = vbYes Then
Set oBook = Nothing
Set oSheet = Nothing
oXL.Quit
Set oXL = Nothing
Else
MsgBox ("Close Excel when finished to return here.")
oXL.Visible = True
End If
DoCmd.SetWarnings True
End Sub
有任何想法吗?
PS它说错误是由Else语句代码生成的