无效或不合格参考 [英] Invalid or Unqualified Reference

查看:158
本文介绍了无效或不合格参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要放入表格名称吗?我需要在多个工作簿中使用这个宏,并且使用类似的工作表,但是选项卡名称是不同的。

  Sub pageSetup()
ActiveSheet.pageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(1#)

End Sub


解决方案

由于Tim没有声明他的回答,您可以使用以下两个选项之一, / p>


  • 格式化 ActiveSheet

  • WorkSheets ActiveWorkBook



ActiveSheet

  Sub TimWilliamsPoints()
With ActiveSheet.pageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(1#)
结束与
End Sub

所有表

  Sub TimWilliam sPoints2()
Dim ws As Worksheet
对于每个ws在ActiveWorkbook.Sheets
与ws.pageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(1#)
结束
下一个ws
End Sub


Do I need to put in the sheet name? I need to use this macro across multiple workbooks with similar worksheets but the tab names are different.

Sub pageSetup()
ActiveSheet.pageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(1#)

End Sub

解决方案

As Tim has not claimed his answer, you could use either of the following two options to either

  • format the ActiveSheet
  • format all WorkSheets in the ActiveWorkBook

ActiveSheet

Sub TimWilliamsPoints()
With ActiveSheet.pageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(1#)
End With
End Sub

All Sheets

Sub TimWilliamsPoints2()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
With ws.pageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLegal
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(1#)
End With
Next ws
End Sub

这篇关于无效或不合格参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆