以定义的缩放级别设置所有Excel工作表

时间:2011-05-10 17:06:41

标签: excel vba excel-2010

我在Excel工作簿(文件)中有超过二十张。是否有一些代码片段或我可以应用/使用的命令,以便所有工作表都可以重置为85%的缩放级别?

3 个答案:

答案 0 :(得分:49)

Sub SetZoom()
    Dim ws As Worksheet

    For Each ws In Worksheets
        ws.Select
        ActiveWindow.Zoom = 85 //change as per your requirements
    Next ws
End Sub

顺便说一句,如果您只是使用选项卡选择工作簿中的所有工作表,则可以将缩放设置为85%,它将应用于所有工作表

答案 1 :(得分:0)

Public DatabaseMethods As New DatabaseTools
Public testRecordset As ADODB.Recordset

Public Sub LoadTables()

   Call DatabaseMethods.SQLCreateDatabaseConnection
   DatabaseMethods.SQLOpenDatabaseConnection ThisWorkbook.FullName

   Set testRecordset = DatabaseMethods.SQLQueryDatabaseRecordset("SELECT * FROM " & DatabaseMethods.TableAddress(ThisWorkbook.Worksheets("Sheet1")))

   DatabaseMethods.SQLCloseConnection
   DatabaseMethods.SQLDestroyDatabaseConnection

End Sub

Public Function SQLQueryDatabaseRecordset(SQLQuery As String) As ADODB.Recordset

   'Create RecordSet
   Set oRs = CreateObject("ADODB.Recordset")
   oRs.LockType = adLockReadOnly

   Sleep 100
   DoEvents

   'Open Record Set by executing SQL
   oRs.Open SQLQuery, oConn

   'Disconnect the recordset
   Set oRs.ActiveConnection = Nothing

   'Return recordset
   Set SQLQueryDatabaseRecordset = oRs

   Set oRs = Nothing

End Function

此代码与上面的代码相似,但是在运行宏之前不必选择工作簿中的所有工作表。除非选择工作表,否则不要使用无法正常工作的Sub SetZoom() Dim ws As Worksheet Application.ScreenUpdating = False 'Optional For Each ws In ActiveWorkbook.Worksheets ws.Activate ActiveWindow.Zoom = 85 Next Application.ScreenUpdating = True End Sub ws.Select,而应改为Next wsws.Activate来设置所有图纸的缩放比例。作为可选选项,Next可以被禁用以用于具有很多工作表的工作簿。

答案 2 :(得分:0)

var currency = "$10,000.00";
var number = Number(currency.replace(/[^0-9.-]+/g,""));

console.log('Number => ', number)