[英]Changing properties of multiple controls in VBA userform permanently
I have a rather large multipage userform in which I want to make changes to some of the tags.我有一个相当大的多页用户表单,我想在其中更改一些标签。 I wrote the following bit of code, only to realize that it only changed said properties during run time - whereas I need them to be changed permanently.
我编写了以下代码,只是意识到它只在运行时更改了所述属性 - 而我需要永久更改它们。
Sub ephemeralNameCh()
Dim p As Integer, lenTag As Integer, lastShMulti As Integer
Dim Ctrl As Control
lastShMulti = uf_Screening.MultiPage1.Count - 1 'Last pg in multipage uf
For p = 0 To lastShMulti
For Each Ctrl In uf_Screening.MultiPage1.Pages(p).Controls
'If tags needs to be change, do so
If Ctrl.Tag <> "" And Left(Ctrl.Tag, 3) <> "P10" And Left(Ctrl.Tag, 3) <> "P11" Then
If Left(Ctrl.Tag, 2) <> "P0" Then
lenTag = Len(Ctrl.Tag)
'New tag
Ctrl.Tag = "P0" & Right(Ctrl.Tag, lenTag - 1)
End If
End If
Next Ctrl
Next p
End Sub
From going through lots of somewhat similar questions I've gathered I probably need to use从我收集到的许多类似的问题中,我可能需要使用
With ThisWorkbook.VBProject.VBComponents("uf_Screening").Designer
But I have not been able to implement it, despite trying several variations.但是,尽管尝试了几种变体,但我仍然无法实现它。 This one
这个
Sub permanentNameCh()
Dim p As Integer, lenTag As Integer, lastShMulti As Integer
Dim Ctrl As Control
lastShMulti = uf_Screening.MultiPage1.Count - 1 'Last pg in multipage uf
With ThisWorkbook.VBProject.VBComponents("uf_Screening").Designer
For p = 0 To lastShMulti
For Each Ctrl In uf_Screening.MultiPage1.Pages(p).Controls
'If tags needs to be change, do so
If Ctrl.Tag <> "" And Left(Ctrl.Tag, 3) <> "P10" And Left(Ctrl.Tag, 3) <> "P11" Then
If Left(Ctrl.Tag, 2) <> "P0" Then
lenTag = Len(Ctrl.Tag)
'New tag
.MultiPage1.Pages(p).Controls(Ctrl.Name).Tag = "P0" & Right(Ctrl.Tag, lenTag - 1)
End If
End If
Next Ctrl
Next p
End With
End Sub
results in Runtime Error 91: Object variable or with block variable not set .导致运行时错误 91: Object 变量或未设置块变量。
Any ideas on how to make this work?关于如何使这项工作的任何想法?
Yes, as you've discovered, you'll need to use the Designer property to make permanent changes.是的,正如您所发现的,您需要使用 Designer 属性进行永久性更改。 Try the following code...
试试下面的代码...
Option Explicit
Sub permanentNameCh()
Dim p As Integer, lenTag As Integer
Dim Ctrl As Control
With ThisWorkbook.VBProject.VBComponents("uf_Screening").Designer.MultiPage1
For p = 0 To .Pages.Count - 1
For Each Ctrl In .Pages(p).Controls
'If tags needs to be change, do so
If Ctrl.Tag <> "" And Left(Ctrl.Tag, 3) <> "P10" And Left(Ctrl.Tag, 3) <> "P11" Then
If Left(Ctrl.Tag, 2) <> "P0" Then
lenTag = Len(Ctrl.Tag)
'New tag
Ctrl.Tag = "P0" & Right(Ctrl.Tag, lenTag - 1)
End If
End If
Next Ctrl
Next p
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.