尝试将范围变量=设置为当前打印区域。
dim rng as range
Set rng = ActiveSheet.PageSetup.PrintArea
除此之外还有更多,但这是我陷入困境的地方 运行时错误' 424': 需要对象
我假设这是因为printarea是文本而我正在使用的变量被设置为范围。如何将我的rng变量设置为printarea范围?
答案 0 :(得分:3)
只要为PrintArea分配了一个值,您就可以将其转换为范围对象,如下所示:
Dim rng As Range
'This has to be set or print area returns a blank string
'which will cause the set statement below to throw an error
ActiveSheet.PageSetup.PrintArea = "A1:B1"
Set rng = Range(ActiveSheet.PageSetup.PrintArea)