2017-04-14 43 views
1

ユーザーにデジタル署名の追加ダイアログを呼び出す簡単なExcelマクロを作成します。私は、デジタル署名の追加ダイアログを表示するだけで、署名自体を追加したくないので、ユーザは自分自身を探す必要はありません。私は解決策を求めていましたが、これはネイティブのExcel VBAでは実行できないことを理解しています。 Windows Shellを直接呼び出す必要があります。それ、どうやったら出来るの?呼び出す方法Excel VBAでデジタル署名ダイアログを追加する

答えて

1

リボンUIを使用しているバージョンがあると仮定してExcelバージョンを指定していません。オプションのカップルがあります - あなたは流暢なUIコントロールの識別子と、このコードを使用することができます:

Option Explicit 

Sub FindControlByFluentUIId() 

    Dim objCtrl As CommandBarControl 
    Dim lngId As Long 

    On Error GoTo ErrHandler 

    ' magic number of Add Digital Signature 
    lngId = 13035 
    ' find that control in the command bars collection 
    ' this line throws an error for some workbooks !? 
    Set obj = Application.CommandBars.FindControl(Office.MsoControlType.msoControlButton, lngId) 
    ' execute 
    If Not obj Is Nothing Then 
     obj.Execute 
    Else 
     MsgBox "Not found" 
    End If 

    End Sub 

ErrHandler: 
    If Err.Number <> 0 Then 
     Debug.Print Err.Description 
    End If 

End Sub 

コードの完全なリストはここにある:https://www.microsoft.com/en-us/download/details.aspx?id=36798

あなたには、いくつかの理由のためのIDを知らなかった場合各コマンドバーの各コントロールコレクションを手動で検索することができます。これはCaptionで、これは探しているものと似ています。キーボードのショートカットを容易にする&のコントロールキャプションと位置の正確なケースがわからない場合があるので、Likeオペレータでワイルドカード検索を行う方がよいでしょう。

あなたはこのような何か試すことができます。

Option Explicit 

Sub TestFindControl() 

    Dim strCaptionWild As String 
    Dim objCtrl As CommandBarControl 

    ' use wildcards to help find the control 
    strCaptionWild = "*add*a*digital*signature*" 

    ' call the function to find by caption 
    Set objCtrl = FindControl(strCaptionWild) 

    ' execute on match 
    If Not objCtrl Is Nothing Then 
     Debug.Print "Command bar index: " & objCtrl.Parent.Index 
     Debug.Print "Control index: " & objCtrl.Index 
     Debug.Print "Real caption: " & objCtrl.Caption 
     objCtrl.Execute 
    Else 
     MsgBox "Not found for caption: " & strCaptionWild 
    End If 

End Sub 

Function FindControl(ByVal strCaption As String) As CommandBarControl 

    Dim objCb As CommandBar 
    Dim objCtrl As CommandBarControl 
    Dim blnFound As Boolean 

    On Error GoTo ErrHandler 

    ' not found the control 
    blnFound = False 

    ' iterate command bars and their controls 
    For Each objCb In Application.CommandBars 
     For Each objCtrl In objCb.Controls 
      ' use like operator check control caption vs input caption 
      ' LIKE enables use of wildcard matching 
      If LCase$(objCtrl.Caption) Like LCase$(strCaption) Then 
       ' found it 
       blnFound = True 
       Exit For 
      End If 
     Next objCtrl 
     If blnFound Then Exit For 
    Next objCb 

    Set FindControl = objCtrl 

    Exit Function 

ErrHandler: 
    Debug.Print Err.Description 
    Set FindControl = Nothing 

End Function 
+0

素晴らしいことです!他のIDを見つけるヒントもありがとう。 – ggv

関連する問題