编译错误:未定义子或函数

时间:2011-05-18 14:36:41

标签: vba

我正在编写VBA宏,但是我收到了上述错误。我看到还有很多其他人都有这个常见的错误,但是,每个人的解决方案似乎都不同。我的宏代码中出现此错误的原因是什么?

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 1/15/2010 by '

    Cells.Replace What:="NULL", Replacement:="", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

    Cells.ReadingOrder = xlLTR

    Cells.VerticalAlignment = xlTop

    Rows("1:1").Font.Bold = True


    With ActiveSheet.PageSetup
        .PrintTitleRows = "$1:$1"
        .LeftHeader = "Abbott Molecular Confidential"
        '.CenterHeader = "Actions (Correction, Corrective and Preventive) Initiated" & Chr(10) & "From 9/1/2009 to 02/21/2011"
        '.CenterHeader = "HCV Actions (Correction, Corrective and Preventive) Initiated" & Chr(10) & "From 9/1/2009 to 02/21/2011"
        '.CenterHeader = "Investigations Created" & Chr(10) & "From 9/1/2009 to 02/21/2011"
        '.CenterHeader = "HCV Investigations Created" & Chr(10) & "From 9/1/2009 to 02/21/2011"
        '.CenterHeader = "ALK Complaints with Report Date" & Chr(10) & "From 1/1/2008 to 12/31/2010"
        '.CenterHeader = "Process Exceptions" & Chr(10) & "From 05/16/2010 to 05/16/2011"
        '.CenterHeader = "ALK Complaints By Lot Number"
        '.CenterHeader = "All Process Nonconformances" & Chr(10) & "From 05/01/2009 to 04/30/2011"
        '.CenterHeader = "2G28-90_Multilevel BOM, 8L070 and 1L31 Exceptions Initiated " & Chr(10) & "From 3/18/2011 to 4/4/2011"
        '.CenterHeader = "Process Exceptions Initiated " & Chr(10) & "From 10/1/2010 to 04/26/2011"
        '.CenterHeader = "Containments " & Chr(10) & "From 9/1/2009 to 02/21/2011"
.CenterHeader = "Complaint Search for RT mS9 US" & Chr(10) & "From 02/09/2009 to 01/05/2011"
        .RightHeader = "Printed on &D &T"
        .RightFooter = "Page &P of &N"
        .LeftFooter = "Data pulled on 05/18/2011"
        .LeftMargin = Application.InchesToPoints(0.75)
        .RightMargin = Application.InchesToPoints(0.75)
        .TopMargin = Application.InchesToPoints(1)
        .BottomMargin = Application.InchesToPoints(1)
        .HeaderMargin = Application.InchesToPoints(0.5)
        .FooterMargin = Application.InchesToPoints(0.5)
        .Orientation = xlLandscape
    End With
End Sub

2 个答案:

答案 0 :(得分:1)

查看VBA文档,了解您的版本的Excel以获取.Replace方法的参数。 * Format参数可能是稍后添加的。

答案 1 :(得分:0)

另一种可能性: 编写新宏时,请确保在开头包含4个注释行,例如:

Sub Macro2() ' ' Macro2()宏 '解析数据第2部分的宏 ' 这摆脱了我的编译错误

相关问题