본문 바로가기

5. VBA,매크로

[엑셀 매크로/VBA] 모든 메모의 사이즈를 잘 보이게끔 조정

매크로를 쓰는 자세한 방법은 문서 맨 아래 링크를 참고하세요 :)

 

지금 워크시트에 적혀있는 모든 메모를, 적절한 위치와 크기로 변환해줍니다.

 - 너무 멀리 떨어져 있거나, 크기가 너무 작아서 안보이는 메모들을 편하게 한번에 바꿔줍니다.

 

너무 멀리 있고 크기도 큰 메모를,
이렇게 제 위치에, 적당한 크기로 바꿔줍니다.

=========아래를 붙여넣기 하세요==========

Sub Reset_Autosize_Comments() 
    Dim cmt As Comment 
    '1 pixel = 0.75 points (for comment) 
    '64 pixels = 8.43 characters, but column width/characters cannot be specified by arithmetic operations 
     
    'Empty cell selection 
    Set Empty_cell = Application.InputBox(prompt:="아무것도 없는 빈 셀을 선택해주세요.", Type:=8) 
    Column_width = Range(Empty_cell.Address).ColumnWidth 
    Range(Empty_cell.Address).Font.Size = "9" 'Typical Comment Font Size 
    Range(Empty_cell.Address).Font.Name = "Tahoma" 'Typical Comment Font Name 
     
    'Size adjustment 
    For Each cmt In ActiveSheet.Comments 
        With cmt 
            .Shape.TextFrame.AutoSize = True 
            If .Shape.Width > 250 Then '150 points = 200 pixels 
                '#Route 1: Height calculation in A1 cell 
                Range(Empty_cell.Address).Value = cmt.Text 
                 
                Range(Empty_cell.Address).ColumnWidth = 30.63 '27.86 characters = 200 pixels 
                Range(Empty_cell.Address).Rows.AutoFit 
                cmt_height = Range(Empty_cell.Address).Rows.Height 
                Range(Empty_cell.Address).Value = "" 
                
                'Re-size of comment 
                .Shape.Width = 187.5 '150 points = 200 pixels 
                .Shape.Height = cmt_height + 10 
            End If 
        End With 
    Next 
     
    'Empty cell recovery 
    Range(Empty_cell.Address).ColumnWidth = Column_width 
     
    'Position adjustment 
    For Each cmt In ActiveSheet.Comments 
        cmt.Shape.Top = cmt.Parent.Top + 5 
        cmt.Shape.Left = cmt.Parent.Offset(0, 1).Left + 5 
    Next 
End Sub

===============================

https://mwoe.tistory.com/71

 

[매크로/VBA] 매크로 코드를 실행하는 법

모든 매크로를 실행하실 때는, 아래의 방법을 따라하시면 됩니다. 1. ALT + F11 을 눌러서, Microsoft Visual Basic for Applications를 열어주세요. 2. 삽입 > 모듈을 눌러서 새 모듈을 삽입하고, 오른쪽 창에..

mwoe.tistory.com