2017-08-09 3 views
0

私はユーザーフォーム 'CemeaFinallist'にチェックボックスとボタンがあります。私は変数としてチェックボックス名の値を使用したい= CNN 'Normal.newmacros.minipro'ノーマルマクロでユーザーフォームの値を使用

enter image description here

に続いては、ユーザーフォームのボタンのスクリプト

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 
+0

コードのどの部分が失敗していますか? – jsotola

+0

実行時エラー '424'オブジェクトが必要です。 'CNN = ctl.Name' –

+1

であなたは' ctl'を宣言していないので、その型はVariantです、 'Dim ctl as Variant'と同じです。値を割り当てていませんが、Nameプロパティを取得してオブジェクトとして使用しようとしています。エラーは、見つかるべき対象がないことを示しています。あなたはMiniPRO 'dim ctlをオブジェクトとして' set ctl = forms( "CemeaFinallist")に 'ctl'オブジェクトを定義する必要があります。checkbox' ....正確なコードではなく、これらの行に沿ったものです – jsotola

答えて

1

ユーザーフォームでは、次のように入力します。

Application.Run MacroName:="NewMacros.MiniPRO", varg1:=ctl.Name 
012あなたは既にコントロールへの参照を持っているので If ctl.value = True Then:あなたはまた、より単純でテスト If Me.Controls(ctl.Name).Value = True Thenを置き換えることができます

Function MiniPRO(ByVal CtlName as String) 
    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 = CtlName 
    ex = ".DOCX" 

    Documents.Open FileName:=path & CNN & ex 
    '... 
End Function 

:Normal.NewMacrosモジュール、使用の際に

+0

コンパイルエラー: 'Application.Run MacroName:= "Normal.NewMacros.MiniPRO"、ctl.Name'の構文エラーです。 –

+0

最初の引数が明示的で、2番目が明示的でなかった可能性があります。 'Application.Run MacroName:=" Normal.NewMacros.MiniPRO "、varg1:= ctl.Name'を試してください。 –

+0

私はUserformで親切に使っているコードを追加しました –

関連する問題