EXCEL VBA遍历控件按钮并逐个添加背景图片
请问这段代码问题出在哪里呢?Sub启动大师()DimQS%,XS%,YS%,num%,pah$,DSAsShapeForQS=1To3ForXS=1To9ForYS=1T...
请问这段代码问题出在哪里呢?
Sub 启动大师()
Dim QS%, XS%, YS%, num%, pah$, DS As Shape
For QS = 1 To 3
For XS = 1 To 9
For YS = 1 To 4
num = QS & XS & YS
On Error Resume Next
Sheet12.Shapes("大师" & num).Visible = True '可以遍历进行显示和隐藏
With Sheet12.Shapes("大师" & num)
' MsgBox Sheet12.Shapes("大师" & num).Name '检测控件名称=正确
pah = ThisWorkbook.Path & "\image\"
.Picture = LoadPicture(pah & "js\" & "js" & num & ".jpg") '插入图片失败
' MsgBox ThisWorkbook.Path & "\image\" & "js\" & "js" & num & ".jpg" '检测图片路径=正确
' Sheet12.大师131.Picture = LoadPicture(pah & "js\" & "js" & num & ".jpg") '测试:直接写控件名可以正常插入图片
End With
Next YS
Next XS
Next QS
End Sub 展开
Sub 启动大师()
Dim QS%, XS%, YS%, num%, pah$, DS As Shape
For QS = 1 To 3
For XS = 1 To 9
For YS = 1 To 4
num = QS & XS & YS
On Error Resume Next
Sheet12.Shapes("大师" & num).Visible = True '可以遍历进行显示和隐藏
With Sheet12.Shapes("大师" & num)
' MsgBox Sheet12.Shapes("大师" & num).Name '检测控件名称=正确
pah = ThisWorkbook.Path & "\image\"
.Picture = LoadPicture(pah & "js\" & "js" & num & ".jpg") '插入图片失败
' MsgBox ThisWorkbook.Path & "\image\" & "js\" & "js" & num & ".jpg" '检测图片路径=正确
' Sheet12.大师131.Picture = LoadPicture(pah & "js\" & "js" & num & ".jpg") '测试:直接写控件名可以正常插入图片
End With
Next YS
Next XS
Next QS
End Sub 展开
1个回答
展开全部
答:Sheet12.Shapes("大师" & num)
返回shape对象,shape对象没有Picture属性。
而“Sheet12.大师131”返回与此 OLE 对象相联系的 OLE 自动化对象,比如:CommandButton。该对象有picture属性。
所以,With Sheet12.Shapes("大师" & num)应改为:
With Sheet12.OLEObjects("大师" & num).Object
才能使用picture属性。
返回shape对象,shape对象没有Picture属性。
而“Sheet12.大师131”返回与此 OLE 对象相联系的 OLE 自动化对象,比如:CommandButton。该对象有picture属性。
所以,With Sheet12.Shapes("大师" & num)应改为:
With Sheet12.OLEObjects("大师" & num).Object
才能使用picture属性。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询