我认为这是一个非常简单的代码,旨在为工作表中的所有活动单元格设置边框(数据将始终驻留在单元格(1,1)中)。但是我遇到了臭名昭著的“运行时错误 1004”,我很困惑。
任何帮助,将不胜感激。
Sub test()
Dim myrange As Range
Dim x, y As Integer
x = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
MsgBox x
'------------------------------'
y = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
MsgBox y
Set myrange = ActiveSheet.Range(Cells(1, 1), Cells(x, y))
With ActiveSheet '<-- erroring here'
.Range(myrange).Select
With Selection.Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
End Sub