LoginSignup
3
4

More than 5 years have passed since last update.

Python OpenpyxlでExcelファイルが壊れるのはオブジェクトが非表示で混入している

Posted at

PythonでOpenpyxlでExcelファイルを読み書きする時、Excelファイルが壊れるときがあります。
原因は、オブジェクト(図形とか)が非表示で残っているからです。
ところが、やっかいなのはホーム-編集-検索と選択-オブジェクトの選択と表示(P)でも表示されないところです。そこで、VBAでVisible=False の Shapesをvisibleにして削除するようにします。

VisibleObject
Sub VisibleShapes()
    Dim spShape As Shape
    Dim spCnt As Long
    For Each spShape In ActiveSheet.Shapes
      If spShape.Visible = False Then
        spShape.Visible = True
        spCnt = spCnt + 1
      End If
    Next
      If spCnt <> 0 Then
        MsgBox spCnt & "個の名前定義が見つかりました。", vbInformation
      Else
        MsgBox "非表示の図形はありません。", vbExclamation
      End If
End Sub
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4