【问题标题】:How to Set ActiveWindow.Zoom in Excel Through Access VBA?如何通过 Access VBA 在 Excel 中设置 ActiveWindow.Zoom?
【发布时间】:2015-06-05 14:44:09
【问题描述】:

我正在尝试在 VBA 中创建一个宏,该宏将通过 Access VBA 格式化 Excel 工作表。我在 Access 中遇到了一些意外,它们无法识别某些 Excel VBA 命令,例如.Select.Interior.Color.ActiveWindow.Zoom。我解决了前两个问题,但有人可以帮我将 Active Zoom 设置为 90% 吗?

Sub ExcelMacro()

Dim xlApp As Object
Dim xlWB As Object

filepath = "\\dom1...xlsm"

Set xlApp = CreateObject("Excel.Application")

xlApp.Workbooks.Open filepath

xlApp.Visible = True

xlApp.Application.DisplayAlerts = True

Set xlWB = xlApp.ActiveWorkbook

xlWB.Sheets(1).ActiveWindow.Zoom = 90

    With xlWB.Sheets(1).Cells
        .Font.Name = "Calibri"
        .EntireColumn.Autofit
    End With

    With xlWB.Sheets(1).range("A1").Entirerow
        .Interior.ColorIndex = 15
        .Font.Bold = True
    End With

'xlApp.Application.DisplayAlerts = True
Set xlApp = Nothing
Set xlWB = Nothing

End Sub

【问题讨论】:

    标签: ms-access vba


    【解决方案1】:

    ActiveWindow 是 Excel 应用程序对象的属性。

    您的代码尝试从工作表对象中使用它...

    xlWB.Sheets(1).ActiveWindow.Zoom = 90
    

    当我用自己的工作表对象测试类似代码时,Access 抛出错误 #438,“对象不支持此属性或方法”

    如果您从应用程序对象变量开始,则不应出现该错误...

    xlApp.ActiveWindow.Zoom = 90
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多