つらつら Excel VBA

私の備忘録です。

ハイパーリンクを削除して保存を繰り返す

Sub ハイパーリンクを削除して保存する処理()

Dim targetWb As Workbook, targetWsh As Worksheet
Dim strFolderPath As String
strFolderPath = ThisWorkbook.Path & "\指定フォルダ\"

'画面の更新を停止して処理を高速化
Application.ScreenUpdating = False

do '複数ファイルを対象とするループ条件をここに記載

Set targetWb = Workbooks.Open("ファイルパス")
Set targetWsh = targetWb.Sheets(1)'対象シート指定

With targetWsh
If .Hyperlinks.Count > 0 Then
.Hyperlinks.Delete 'ハイパーリンクの削除
End If
End With

'ファイルの保存と終了
If targetWb.Saved = False Then targetWb.Save
targetWb.Close

Set targetWsh = Nothing
Set targetWb = Nothing

Loop

Application.ScreenUpdating = True
Application.StatusBar = False 'Excelに返す

End Sub

'上記のままでは正しく動きません。無限ループになったら[Esc]で抜けましょう。