Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 2003 VBA(可扩展性):运行时更改VBComponent/Usetform名称时发生路径/文件访问错误_Vba_Excel_Extensibility - Fatal编程技术网

Excel 2003 VBA(可扩展性):运行时更改VBComponent/Usetform名称时发生路径/文件访问错误

Excel 2003 VBA(可扩展性):运行时更改VBComponent/Usetform名称时发生路径/文件访问错误,vba,excel,extensibility,Vba,Excel,Extensibility,我正在尝试创建自定义/高级消息框(因为我可以,或者应该能够) 我在wenb上查看了这些资源: (一) (二) 我已经在我的VB项目中创建了一个名为“MessageBox”的类模块,它添加了一个UserForm,应该添加一个按钮,然后显示表单……还添加了Visual Basic应用程序扩展性引用 但是当我尝试更改用户名时,^&%^代码一直给我一个路径/文件访问错误 我做错了什么 Private oForm As Object Function Show(Optional ByVal Messag

我正在尝试创建自定义/高级消息框(因为我可以,或者应该能够)

我在wenb上查看了这些资源:

(一)

(二)

我已经在我的VB项目中创建了一个名为“MessageBox”的类模块,它添加了一个UserForm,应该添加一个按钮,然后显示表单……还添加了Visual Basic应用程序扩展性引用

但是当我尝试更改用户名时,^&%^代码一直给我一个路径/文件访问错误

我做错了什么

Private oForm As Object

Function Show(Optional ByVal MessageText As String, Optional ByVal Buttons As     VbMsgBoxStyle = vbOKOnly, Optional ByVal Caption As String) As VbMsgBoxResult

Dim oControl() As MSForms.CommandButton
Dim x As Integer, MaxWidth As Long

Set oForm = Application.VBE.ActiveVBProject.VBComponents.Add(vbext_ct_MSForm)

With oForm
    .Properties("Height") = 200
    .Properties("Width") = 300
    .Properties("Caption") = Caption
        If Buttons = vbDefaultButton1 Then
            ReDim oControl(0)
            Set oControl(0) = .Designer.Controls.Add("Forms.CommandButton.1")
            With oControl(0)
                .Caption = "OK"
                .Height = 18
                .Width = 44
                .Left = MaxWidth + 147
                .Top = 6
                .Name = "cmdOK"
            End With
        End If
        .Name = "cMessageBox"
    End With
    'Application.VBE.ActiveVBProject.VBComponents("UserForm1").Name="cMessageBox"

    ' ActiveWorkbook.VBProject.VBComponents ("cMessageBox")
    With oForm.CodeModule
        x = .CountOfLines
        .InsertLines x + 1, "Sub cmdOK_Click()"
        .InsertLines x + 2, "    Unload Me"
        .InsertLines x + 3, "End Sub"
    '        .InsertLines x + 4, ""
    '        .InsertLines x + 5, "Sub CommandButton2_Click()"
    '        .InsertLines x + 6, "    Unload Me"
    '        .InsertLines x + 7, "End Sub"
    End With
    Call ShowIt

    End Function

    Private Sub ShowIt()
    cMessageBox.Show
    End Sub

您是否尝试过将表单对象声明为
MSForms.UserForm
VBComponent
?谢谢,我会尝试一下。我记得大约一年前发生过这种情况,我确信是类似于这种情况解决了它。不管怎样,祝你好运!这是由于已知的VBA错误造成的: