【发布时间】:2018-05-24 20:45:20
【问题描述】:
以下代码在 Excel 2013 中运行良好。我们的 IT 人员为我们安装了一台带有 Excel 2016 的新计算机。现在打开文件时出现错误“运行时错误 '1004': Unable to set the CenterHeaderproperty of the PageSetup 类"
当我尝试录制宏以查看 Excel 2016 是否执行不同操作时,代码看起来与此处相同,并且此代码在 2013 年仍然运行良好。
Private Sub Workbook_Open()
Dim Obj As Object
AWb = Application.ActiveWorkbook.Name
If AWb = "UCSB Service Form.xlsm" Then
Application.ScreenUpdating = False
Sheets("Form").Activate
DateFormat = Format(Date, "mm/dd/yy;@")
Range("F2") = DateFormat
Range("F36") = DateFormat
Cells.Validation.Delete
'Sets record number
Record = "Pending"
Range("H6") = "'" & Record
ActiveSheet.PageSetup.CenterHeader = "Record: " & Record
'<<< Debug indicates this line
'Run-time error '1004': Unable to set the CenterHeaderproperty of the PageSetup class
'Open blank form
Range("F3:F7").ClearContents
Range("E9:F10").ClearContents
Range("E12:F18").ClearContents
Range("E20:F23").ClearContents
Range("E26:F29").ClearContents
Range("K2:K5").ClearContents
Range("H4:I6").ClearContents
Range("G9:J25").ClearContents
Range("I27:I31").ClearContents
Range("K27:K31").ClearContents
Range("K27:K31").ClearContents
Range("G34:I39").ClearContents
Range("I40").ClearContents
Range("K40").ClearContents
Range("K33:K36").ClearContents
'Clear Highlighting
Range("F3:F7").Interior.Color = xlNone
Range("E9:F9").Interior.Color = xlNone
Range("E12:F13").Interior.Color = xlNone
Range("E14:F17").Interior.Color = xlNone
Range("E18:F18").Interior.Color = xlNone
Range("E20:F23").Interior.Color = xlNone
Range("H4:I4").Interior.Color = xlNone
Application.ScreenUpdating = True
Range("A1").Select
Range("F3").Select
Application.ScreenUpdating = False
Range("H6") = "'" & Record
Set Obj = ActiveSheet.CommandButton1
Obj.Caption = "Save"
Call M_Lists.S_Lists
End If
'Updated 4/25/18
End Sub
【问题讨论】:
-
您的新电脑上是否设置了打印机?
-
哦哈哈,谢谢。是的,上面设置了打印机,但我们一直遇到打印问题。
-
这太奇怪了!我将主打印机设置为默认值,现在一切正常!谢谢!
-
我将评论转换为答案。考虑单击它旁边的复选标记,让其他人知道它可以解决您的问题,以防他们遇到同样的问题!
标签: excel excel-2013 excel-2016 vba