매크로를 이용한 Excel제어명령 작성법
Excel의 매크로를 이용하면 VB에서 Excel을 제어하는 명령어를 작성 하기가 쉽다.
방법은 아래와 같다.
1) 도구(T) 메뉴의 매크로에서 새 매크로 기록..(R)을 선택한 후 매크로명을 입력
2) Excel Sheet에서 작업을 하면 작업 (내역이 매크로에 기록 됨)
3) 매크로 기록을 중단하고 도구(T) 메뉴의 매크로에서(매크로를 선택) 매크로명을
선택한 후 편집 버튼을 누르면 매크로가 보임
-> 매크로를 복사해서 VB에서 편집하면 작업 끝...
매크로 )
ActiveSheet.Cells(iRow + 1, iCol).Select
'
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
' Left
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
VB)
Dim xApp As New Excel.Application
xApp.Visible = True ' Excel 표시
xApp.Workbooks.Add ' Work Sheet 추가
xApp.ActiveSheet.Cells(iRow + 1, iCol).Select
'
xApp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
xApp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
' Left
With xApp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With