简体   繁体   English

工作簿上的代码_打开会影响工作表上图像的初始视图

[英]Code on Workbook_Open effecting initial view of images on worksheets

I have set Worksheet.EnableCalculation property to manual for a number of sheets on opening the workbook. 对于打开工作簿时的许多Worksheet.EnableCalculation我已经将Worksheet.EnableCalculation属性设置为手动。 In the process I also change the size of 2 shapes on each of these sheet (Make one image big and one small). 在此过程中,我还更改了每张纸上2种形状的大小(将一张图像放大一幅,然后缩小一幅)。 These shapes also have macros assigned to them. 这些形状还具有分配给它们的宏。 To add more confusion, one sheet can be fine on opening the workbook and the rest not. 为了增加混乱,打开工作簿时可以用一张纸,而其余的则不能。 The sheet that is OK is not always the same sheet and I can not work out how that sheets differs at that time from the others. 可以的工作表并不总是相同的工作表,我无法弄清当时的工作表与其他工作表有何不同。 It is not that it is active at time of saving. 它不是在保存时处于活动状态。

This works fine but when viewing the sheets on opening the workbook these shapes as well as all other shapes on the sheet (which are also used as macro buttons) appear to have moved position on the sheet (up and left). 这很好用,但是在打开工作簿时查看图纸时,这些形状以及图纸上的所有其他形状(也用作宏按钮)似乎在图纸上已移动位置(上下)。 However, by just zooming in/out the buttons appear back in their correct position. 但是,仅通过放大/缩小按钮即可将其重新显示在正确的位置。

I have added code to set the zoom during the Workbook_Open event to set the zoom but that does not stop this anomaly appearing. 我在Workbook_Open事件中添加了用于设置缩放Workbook_Open代码,以设置缩放Workbook_Open ,但这并不能阻止此异常的出现。 Putting the zoom into Workbook_SheetActivate also does not effect the issue 将缩放比例放入Workbook_SheetActivate也不会影响该问题

It does not have any obvious effect on the workbook and is not an issue once the zoom has been applied manually to each effected sheet but it does not look good when it opens. 它将缩放对工作簿没有明显影响,并且在手动将缩放应用于每个受影响的工作表后也不会成为问题,但是在打开时看起来并不好。

Private Sub Workbook_Open()

' ***** STOPS automatic formular updating
' x - Defined Cell Names  Lock_LABEL
' x - Image               Lock_ON    Lock_OFF

Application.ScreenUpdating = False  ' do not see screen updating

Sheets("5_Angebot").Select

    ' Turn automatic forular updating OFF
    ActiveSheet.EnableCalculation = False

    ' Make ON lock Small
    ActiveSheet.Shapes.Range(Array("Lock_ONN")).Select  ' x
    Selection.ShapeRange.Height = 28.3464566929

    ' Make OFF lock Big
    ActiveSheet.Shapes.Range(Array("Lock_OFF")).Select  ' x
    Selection.ShapeRange.Height = 46.7716535433

    ' Label
    Range("ANLock_LABEL").Select                        ' x
    ActiveCell.FormulaR1C1 = "Auto Update is OFF"
    Selection.HorizontalAlignment = xlLeft
    With ActiveCell.Characters(Start:=15, Length:=4).Font
        .FontStyle = "Fett"
        .Size = 10
        .Color = -16776961
    End With
    Range("B1").Select

    Sheets("5_Auftragsb").Select

    ' Turn automatic forular updating OFF
    ActiveSheet.EnableCalculation = False

    ' Make ON lock Small
    ActiveSheet.Shapes.Range(Array("Lock_ONN")).Select  ' x
    Selection.ShapeRange.Height = 28.3464566929

    ' Make OFF lock Big
    ActiveSheet.Shapes.Range(Array("Lock_OFF")).Select  ' x
    Selection.ShapeRange.Height = 46.7716535433

    ' Label
    Range("AULock_LABEL").Select                        ' x
    ActiveCell.FormulaR1C1 = "Auto Update is OFF"
    Selection.HorizontalAlignment = xlLeft
    With ActiveCell.Characters(Start:=15, Length:=4).Font
        .FontStyle = "Fett"
        .Size = 10
        .Color = -16776961
    End With
    Range("B1").Select

    Sheets("5_Abschluss").Select

    ' Turn automatic forular updating OFF
    ActiveSheet.EnableCalculation = False

    ' Make ON lock Small
    ActiveSheet.Shapes.Range(Array("Lock_ONN")).Select  ' x
    Selection.ShapeRange.Height = 28.3464566929

    ' Make OFF lock Big
    ActiveSheet.Shapes.Range(Array("Lock_OFF")).Select  ' x
    Selection.ShapeRange.Height = 46.7716535433

    ' Label
    Range("ABLock_LABEL").Select                        ' x
    ActiveCell.FormulaR1C1 = "Auto Update is OFF"
    Selection.HorizontalAlignment = xlLeft
    With ActiveCell.Characters(Start:=15, Length:=4).Font
        .FontStyle = "Fett"
        .Size = 10
        .Color = -16776961
    End With
    Range("B1").Select

    Sheets("7_FAX_KWagen").Select

    ' Turn automatic forular updating OFF
    ActiveSheet.EnableCalculation = False

    ' Make ON lock Small
    ActiveSheet.Shapes.Range(Array("Lock_ONN")).Select  ' x
    Selection.ShapeRange.Height = 28.3464566929

    ' Make OFF lock Big
    ActiveSheet.Shapes.Range(Array("Lock_OFF")).Select  ' x
    Selection.ShapeRange.Height = 46.7716535433

    ' Label
    Range("KWLock_LABEL").Select                        ' x
    ActiveCell.FormulaR1C1 = "Auto Update is OFF"
    Selection.HorizontalAlignment = xlLeft
    With ActiveCell.Characters(Start:=15, Length:=4).Font
        .FontStyle = "Fett"
        .Size = 10
        .Color = -16776961
    End With
    Range("B1").Select

    ' Turn automatic forular updating OFF
    ActiveSheet.EnableCalculation = False
    Range("B1").Select

    MsgBox "                     Hallo " & vbNewLine & vbNewLine & _
           "   Automatic updating is currently" & vbNewLine & _
           "                   turned off"

     ' Set Zoom on all sheets
    Dim ws As Worksheet

    For Each ws In Worksheets
        ws.Select
        ActiveWindow.Zoom = 120
    Next ws

    Sheets("3_Data Form").Select

    Application.ScreenUpdating = True  ' see screen updating

End Sub

I didn't solve anything, just made a more concise version of your code. 我什么都没解决,只是做了一个更简洁的代码版本。

Private Sub Workbook_Open()

' ***** STOPS automatic formular updating

' x - Defined Cell Names  Lock_LABEL
' x - Image               Lock_ON    Lock_OFF
Dim ShName(3, 1) As String
ShName(0, 0) = "5_Angebot"
    ShName(0, 1) = "ANLock_LABEL"
ShName(1, 0) = "5_Auftragsb"
    ShName(1, 1) = "AULock_LABEL"
ShName(2, 0) = "5_Abschluss"
    ShName(2, 1) = "ABLock_LABEL"
ShName(3, 0) = "7_FAX_KWagen"
    ShName(3, 1) = "KWLock_LABEL"
Dim ws As Worksheet
Application.ScreenUpdating = False                                        ' do not see screen updating
For Each ws In ActiveWorkbook.Worksheets
    ws.Select
    ActiveWindow.Zoom = 120                                               ' your zoom, seems unnecessary
    '.Range("B2").Select                                                  ' this one really isn't necessary
    Cells(ActiveWindow.SplitRow + 1, ActiveWindow.SplitColumn + 1).Select ' fancy way instead of B2, selects cell after frozen panels, still unnecessary
Next

For i = 0 To UBound(ShName(, 0))                                          ' not sure about this UBound, it should be the fancy way of 3
Set ws = Sheets(ShName(i, 0))
With ws
    .EnableCalculation = False                                            ' Turn automatic forular updating OFF
    .Shapes.Range(Array("Lock_ONN")).ShapeRange.Height = 28.3464566929    ' Make ON lock Small
    .Shapes.Range(Array("Lock_OFF")).ShapeRange.Height = 46.7716535433    ' Make OFF lock Big
    With .Range(ShName(i, 1))                                             ' Label     ' I'm not sure about this one, should work anyway; the dot might not be necessary
        .FormulaR1C1 = "Auto Update is OFF"
        .HorizontalAlignment = xlLeft
        With .Characters(Start:=15, Length:=4).Font
            .FontStyle = "Fett"
            .Size = 10
            .Color = -16776961
        End With
    End With
End With
Next i
MsgBox "                     Hallo " & vbNewLine & vbNewLine & _
           "   Automatic updating is currently" & vbNewLine & _
           "                   turned off"
Sheets("3_Data Form").Select
Application.ScreenUpdating = True                                         ' see screen updating
End Sub

Ok, not exactly solved the issue but have got the workaround to hide the problem. 好的,不能完全解决问题,但是有解决方法可以隐藏问题。

I have added a second zoom in the code. 我在代码中添加了第二个缩放。

It looks like when actioning the zoom coding it only affected the sheets that were not already set on the zoom value which is why it appeared random to which sheets were opening with the screen looking OK. 似乎在执行缩放编码时,它仅影响尚未设置在缩放值上的图纸,这就是为什么在屏幕看起来确定的情况下,随机打开哪些图纸的原因。 When changing it twice it effectively results in them all being 'changed' and hence resolving the screen updating glitch. 两次更改时,实际上会导致所有“更改”,从而解决了屏幕更新故障。

It will work for now but appreciate that it is just a bandaid. 它现在可以使用,但是请欣赏它只是一个创可贴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM