a_m*_*m0d 1 excel vba excel-vba
我有一些代码不断导致
Error 70: Permission Denied
Run Code Online (Sandbox Code Playgroud)
在我的VBA代码中.我无法理解为什么,因为我知道工作表是不受保护的,我可以对其进行更改.有问题的代码是
sh.Name = "square"
Run Code Online (Sandbox Code Playgroud)
它尝试重命名已从另一个工作表复制并粘贴到工作表中的形状 - 工作表中没有其他形状具有该名称,因为在这些代码之前,我已经删除了具有该名称的所有形状.
有关什么可能导致此权限错误的任何建议?
通常,这是因为尝试两次使用相同的名称.尝试这样做:
Sub Example()
Dim lngIndx As Long
Dim ws As Excel.Worksheet
Dim shp As Excel.Shape
Set ws = Excel.ActiveSheet
Set shp = ws.Shapes.AddShape(msoShapeOval, 174#, 94.5, 207#, 191.25)
If NameUsed(ws, "Foo") Then
lngIndx = 2
Do While NameUsed(ws, "Foo" & CStr(lngIndx))
lngIndx = lngIndx + 1
Loop
shp.name = "Foo" & CStr(lngIndx)
Else
shp.name = "Foo"
End If
End Sub
Private Function NameUsed(ByVal parent As Excel.Worksheet, ByVal name As String) As Boolean
Dim shp As Excel.Shape
Dim blnRtnVal As Boolean
name = LCase$(name)
For Each shp In parent.Shapes
If LCase$(shp.name) = name Then
blnRtnVal = True
Exit For
End If
Next
NameUsed = blnRtnVal
End Function
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
48052 次 |
| 最近记录: |