我有用戶窗體'CemeaFinallist',其中有複選框和按鈕。我想用複選框名稱的值作爲變量= CNN在 'Normal.newmacros.minipro'在普通宏中使用userform值
以下是用戶窗體按鈕腳本
Private Sub Shift_Click()
CemeaFinallist.Hide
Dim ctl As Control
Dim j As Long
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.CheckBox Then
If Me.Controls(ctl.Name).Value = True Then
If ctl.Caption = "Select All" Then
Else
Application.Run MacroName:="Normal.NewMacros.minipro"
End If
End If
End If
Next
Application.ScreenUpdating = True
End Sub
以下是Normal.NewMacros宏觀
Sub MiniPRO()
Application.ScreenUpdating = False
Dim path As String
Dim CNN As String
Dim ex As String
Dim News As String
Dim SD As String
path = "C:\Documents and Settings\Administrator\Desktop\EMEA CEEMEA\EMEA FOR DAILY USE\"
CNN = ctl.Name 'at this stage Run Time Error '424' Object required'
ex = ".DOCX"
Documents.Open FileName:=path & CNN & ex
哪部分代碼失敗? – jsotola
需要運行時錯誤'424'對象。在'CNN = ctl.Name' –
你沒有聲明'ctl',所以它的類型是Variant,和'Dim ctl as Variant'一樣。您尚未爲其分配任何值,但您試圖通過檢索Name屬性將其用作對象。錯誤表示沒有找到任何對象。你需要在MiniPRO中定義'ctl'對象'dim ctl as object''set ctl = forms(「CemeaFinallist」)。checkbox' ....不是確切的代碼,而是沿着這些行的東西 – jsotola