出现运行时错误错误'1004':无法设置PageSetup类的PrintTitleRows属性

问题描述 投票:0回答:1

我正在为工作表的页面设置创建一个子项。弹出.PrintTitleRows = Match的错误消息。如果我删除那条线,则子功能会完美运行。我在Microsoft support上调查了此错误,它说:“当计算机上未安装打印机驱动程序时,会发生此问题。如果未安装打印机驱动程序,则Excel无法设置或获取页面设置属性。”有趣的是,该页面列出了.PageSetup类中的其他属性,包括.CenterHeader.PrintQuality.Orientation以及我的代码中的许多其他属性。如果针对与错误类型相对应的每个属性都出现此错误,则更有意义,但只有.PrintTitleRows会这样做。

这是我的代码:

Sub PageSetup_General2()
Dim WS As Worksheet
Dim Match As Range

Set WS = ActiveWorkbook.ActiveSheet
Application.PrintCommunication = True

Set Match = WS.Cells.Find(What:="Source #", LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
        'Find Range for .PrintTitleRows

With WS.PageSetup
        .CenterHeader = "&F"
        .LeftFooter = "Prepared by " & Application.UserName
        'Sets username, to check what your username is, go to File>Options>General
        .CenterFooter = "&D"
        .RightFooter = "Page &P"
        .LeftMargin = Application.InchesToPoints(0.25)
        .RightMargin = Application.InchesToPoints(0.25)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        'Sets arrow margins
        .PrintQuality = 600
        .Orientation = xlLandscape
        'Sets Landscape
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
        .PrintTitleRows = Match
        'Yields error: "Run-time error '1004': "Unable to set the PrintTitleRows property of the PageSetup class"
End With
End Sub

我搞砸了Application.PrintCommunication,并仔细检查了我的打印机驱动程序是否已安装,但无济于事...对此子的最新动向有何想法?

excel vba
1个回答
0
投票

尽管已在评论中解决,但最好的答案是这样;

[PrintTitleRows属性,每MS documentation

返回或设置包含要在每个页面顶部重复的单元格的行,以宏语言在A1样式表示法中作为字符串。读/写字符串。

同样,要获得A1样式的符号,请使用Range.Address属性-在您的情况下为Match.Address。假设您的范围代表A5D5的单元格,它将返回Match.Address$A$5:$D$5

您可以参考.Address property documentation here

如果要返回不带$绝对引用的地址,请将rowAbsolutecolumnAbsolute参数设置为False,即.Address False, False将返回A5:D5

© www.soinside.com 2019 - 2024. All rights reserved.