표준스타일을 제외한 모든 스타일을 제거하는 매크로 함수

모듈에 아래 함수를 만들고

매크로로 지정하면....끝.

 

 

Sub RebuildDefaultStyles()
'The purpose of this macro is to remove all styles in the active
'workbook and rebuild the default styles. "Normal" cannot be
'deleted. Therefore the macro does not attempt to delete it.
'It rebuilds the default styles by merging them from a new workbook.
 'Dimension variables. // 변수선언
  Dim MyBook As Workbook
  Dim tempBook As Workbook
  Dim CurStyle As Style
 On Error Resume Next '//오류가 발생하도 무시하고 계속 진행
 'Set MyBook to the active workbook.
  Set MyBook = ActiveWorkbook

 'Delete all the styles in the workbook.
  For Each CurStyle In ActiveWorkbook.Styles
      If Not (CurStyle.BuiltIn) Then CurStyle.Delete  '//기본 스타일이 아닐 경우에만 삭제
  Next CurStyle

 'Open a new workbook.
  Set tempBook = Workbooks.Add

 'Disable alerts so you may merge changes to the Normal style
  'from the new workbook.

  Application.DisplayAlerts = False
 'Merge styles from the new workbook into the existing workbook.
  MyBook.Styles.Merge Workbook:=tempBook

 'Enable alerts.
     Application.DisplayAlerts = True

 'Close the new workbook.
  tempBook.Close

End Sub



+ Recent posts