【发布时间】:2021-12-22 19:08:24
【问题描述】:
我正在尝试获取用户表单上文本框的值并将其分配给字符串变量,然后使用 String 类的 Insert 方法将连字符插入该字符串变量。每次运行此代码时,我都会收到错误“无效的限定符”,并突出显示 AcctUnitString。
Dim AcctUnitString As String
AcctUnitString = AcctUnit.Text
AcctUnitString = AcctUnitString.Insert(2, "-")
Debug.Print (AcctUnitString)
AcctUnit 是用户表单上文本字段的名称。有什么想法可能导致此错误,或者有什么更好的方法来做我想做的事情?
用户将在文本框中输入一个 13 位代码(例如 9200030015001),我想将其格式化为:92-0003-001-5001。任何帮助是极大的赞赏。谢谢!
【问题讨论】:
-
在我上面给出的示例中,如果我要在文本框中输入 9200030015001 而只是
Debug.Print(AcctUnit.Text),则值为 9200030015001。
标签: vba