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.
There's no zoom
property on worksheet, i think you need to change zoom
property of a window!
You can use the following code
Sheets("Sheet Name").Select
ActiveWindow.Zoom = 30 ' Zoom Set to 30%
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.