使用Excel VBA修改另一个工作簿中的.zoom属性(Using Excel VBA to modify .zoom property in another workbook)

编程入门 行业动态 更新时间:2024-10-28 02:23:53
使用Excel VBA修改另一个工作簿中的.zoom属性(Using Excel VBA to modify .zoom property in another workbook)

我正在编写一个复杂的VBA应用程序,它从一个工作簿导入数据,在导入时转换数据。 作为此导入过程的一部分,进行计算以获取某个单元格的.text值(并且不能将其更改为.value),但是这意味着如果源工作簿被缩小,则导入#### #### values,因为它是显示的内容。

我试图修改源工作簿的活动表中的.zoom设置为100%缩放。 下面使用的代码示例如下。

Dim SourcePath as String Dim SourceWorkbook as Object FilePath = Application.GetOpenFilename 'Opens dialogue for user to select source If FilePath <> "" Then 'Checks that the filepath is completed SourcePath = FilePath 'Stores the filepath for source End If Set SourceWorkbook = Workbooks.Open(SourcePath) SourceWorkbook.ActiveWorksheet.Zoom = 100

我得到一个运行时错误91:对象变量或With块变量没有设置错误,所以我假设这里的逻辑很差。

任何人都可以建议一种使这项工作的方法吗? 谢谢你的期待。

I am writing a complex VBA app that imports data from one workbook, transforming the data as it imports. As part of this import process, a calculation is made that picks up the .text value of a certain cell (and this cannot be changed to .value), however this means if the source workbook is zoomed out, this imports ######## values, as that is what is displayed.

I am trying to modify the .zoom setting in the activesheet of the source workbook to be 100% zoom. An example of the code used is below.

Dim SourcePath as String Dim SourceWorkbook as Object FilePath = Application.GetOpenFilename 'Opens dialogue for user to select source If FilePath <> "" Then 'Checks that the filepath is completed SourcePath = FilePath 'Stores the filepath for source End If Set SourceWorkbook = Workbooks.Open(SourcePath) SourceWorkbook.ActiveWorksheet.Zoom = 100

I am getting a run-time error 91: Object variable or With block variable not set error, so I am assuming the logic here is poor.

Can anybody suggest a way of making this work? Thanks in anticipation.

最满意答案

您可以使用以下代码

Sheets("Sheet Name").Select ActiveWindow.Zoom = 30 ' Zoom Set to 30%

You can use the following code

Sheets("Sheet Name").Select ActiveWindow.Zoom = 30 ' Zoom Set to 30%

更多推荐

本文发布于:2023-04-29 07:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335850.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   工作   Excel   VBA   zoom

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!