어떤 모양이 그 위에 놓여 있는지 확인하고 싶은 범위가 있습니다.Excel 2003, 왼쪽 위 및 아래 오른쪽 범위를 얻는 방법?
나는 (http://www.mrexcel.com/forum/excel-questions/317711-visual-basic-applications-identify-top-left-cell-selected-range.html) 온라인 스크립트를 발견하지만, 엑셀 2003 지금까지 발견 된 스크립트에서 adapated되어있는 코드가 작동하지 않습니다 :
Public Function removeOLEtypesOfType() As Boolean
On Error Resume Next
Dim objTopLeft As Range, objBotRight As Range _
, objRange As Range, objShape As Shape
Set objRange = Sheet1.Range(COLUMN_HEADINGS)
objRange.Select
With Selection
Dim intFirstCol As Integer, intFirstRow As Integer _
, intLastCol As Integer, intLastRow As Integer
intFirstCol = .Column
intFirstRow = .Row
Set objTopLeft = .Cells(intFirstRow, intFirstCol) '.Address(0, 0)
intLastCol = .Columns.Count + .Column - 1
intLastRow = .Rows.Count + .Row - 1
Set objBotRight = .Cells(intLastRow, intLastCol) '.Address(0, 0)
If objTopLeft Is Nothing Or objBotRight Is Nothing Then
MsgBox "Cannot get topleft or bottom right of range!", vbExclamation
removeOLEtypesOfType = False
Exit Function
End If
For Each objShape In ActiveSheet.Shapes
Dim objTLis As Range
Set objTLis = Intersect(objTopLeft, objShape.TopLeftCell)
If Not objTLis Is Nothing Then
Dim objBRis As Range
Set objBRis = Intersect(objBotRight, objShape.BottomRightCell)
If Not objBRis Is Nothing Then
objShape.Delete
End If
End If
Next
End With
Sheet1.Cells(1, 1).Select
removeOLEtypesOfType = True
End Function
objTopLeft 및 objBotRight는 모두 아무것도 없습니다 , COLUMN_HEADINGS는 범위 이름을 포함합니다.
디버거에서 intFirstCol, intFirstRow, intLastCol 및 intLastRow를 확인했는데 정확합니다.
편집 ... .Address를 주석 처리하여 topleft 및 botright 범위가 모두 반환되지만 .Address in을 사용하면 둘 다 Nothing입니다. 반환 된 범위가 올바른 위치로 표시되지 않습니다.
intFirstCol = 3
intFirstRow = 11
intLastCol = 3
intLastRow = 186
상기 올바른지가 그러나 : 공급 된 범위 예를 들어
너를 상기 올바르지 않은
objTopLeft.Column = 5
objTopLeft.Row = 21
objBotRight.Column = 5
objBotRight.Row = 196
는 열이 +2이고 행이 +10이다, 왜?
은 엑셀 범위/모양 관련 위치/스크린 샷을 게시 – user3598756