You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何使用BorderAround()方法时出现‘Object Required’错误?

解决VBA中Range.BorderAround方法报错“Object Required”的问题

错误原因

你代码第三行报错是因为 BorderAround 是Range对象的方法,不是可直接访问属性的对象,不能像 Borders 那样链式访问 .LineStyle 属性。Borders 返回的是一个Borders集合对象,所以可以直接设置其LineStyle;而BorderAround需要通过调用方法时传入参数来定义边框样式。

修正后的代码

Set Figr = ActiveWorkbook.Sheets("FIGURES")
' 设置所有内部和外部边框为连续线条
Figr.Range("B31", Figr.Range("B31").Offset(9, 5)).Borders.LineStyle = xlContinuous
' 调用BorderAround方法设置外边框为粗线
Figr.Range("B31", Figr.Range("B31").Offset(9, 5)).BorderAround LineStyle:=xlContinuous, Weight:=xlThick

关键区别说明

  • Borders:是Range的属性,返回该区域所有边框(包括内部横、竖线和外边框)的集合,所以可以直接修改集合的LineStyle等属性。
  • BorderAround:是Range的方法,专门用于给整个区域添加外边框,需要通过参数指定样式、线条粗细、颜色等,语法为:
    expression.BorderAround([LineStyle], [Weight], [ColorIndex], [Color])
    
    你可以按需传入参数,比如只指定线条粗细可以写:BorderAround Weight:=xlThick(默认LineStyle是xlContinuous)。

内容的提问来源于stack exchange,提问作者user19646

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 23:54:58