2017-11-21 6 views
0

私の場合の解決策を探しています。コンボボックスで選択した値からPDF文書を開く - ユーザフォーム

私は私の部署のためにマクロを作成しているところです。私はちょうど立ち往生しています。

私は6つの異なるキャリアパスを持っており、pdfドキュメントをコンボボックスの値にリンクしたいと考えています。これは、それが見えるものです。場合は、

は私は何をしたいです

data

combobox

コンボボックスのデータが隠されている他のワークシートである:私は、下図のようにコンボボックスを持っていますコンボボックス内の値は、例えば "Assertiveness in Practity"であり、コマンドボタン "Read"をクリックした後、B1欄にあるpdfファイルを開きたいと思います。 chosen value

path

それをする方法はありますか?

答えて

0

はい、ファイルを開くことができます。これを行う方法の例とコードをテストするサブルーチンを次に示します。下記のコードを変更してください。

既存のボタンを変更するクリックすると、図のような「OpenFile」行が追加されます。 完全なパスとファイル名を渡します。 あなたのcomboBoxには、comboBoxの列としてのパスがあるとしますか?ない 場合は、非表示の列

Private Sub cmdRead_Click() 
     ' whatever code you have or need 
     OpenFile Me.cboXXXX.Column(1)  ' Change to the name of your combobox AND column # of Full Path 
     ' whatever other code you want 
    End Sub 


'---- Create a new module and paste all of the following code in it 

Option Explicit 
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long 

Public Function OpenFile(sFileName As String) 
On Error GoTo Err_OpenFile 

    OpenFile = ShellExecute(Application.hWndAccessApp, "Open", sFileName, "", "C:\", 1) 

Exit_OpenFile: 
    Exit Function 

Err_OpenFile: 
    MsgBox Err.Number & " - " & Err.Description 
    Resume Exit_OpenFile 

End Function 

Public Function TestOpeningFile() 
On Error GoTo Err_TestOpeningFile 

    OpenFile "C:\Windows\Win.ini" 

Exit_TestOpeningFile: 
    Exit Function 

Err_TestOpeningFile: 
    MsgBox Err.Number & " - " & Err.Description 
    Resume Exit_TestOpeningFile 

End Function 
+0

申し訳ありません、情報をありがとうございます。私は、コマンドボタンに任意の行が表示されないので、私はコマンドボタンに上記のコードを割り当てる必要がありますか?または、私はちょうどユーザーフォームに挿入する必要がありますか? – Janek

+0

私は、コントロールの名前を変更する必要がある '一般的な呼び出し'を使用して、1分以内に回答を更新します。それはトリックを行うだろう... –

+0

とにかく私はウェブサイト上のマクロをアップロードすることができますか?私は、何が起こっているかを見るのがはるかに簡単になると思う。 – Janek

0
Sub Training() 

Call Workbook_Open 

End Sub 

Private Sub Workbook_Open() 'open the msgbox with the message and username. 
MsgBox "   " & ("Welcome") & vbCrLf & vbCrLf & "  " & Application.UserName 

Userform1.Show 

End Sub 



In Userform I got: 


    Private Sub Analytical_Button_Click() 

Analytical_userform.ComboBox1.Clear 

For Each cell In Range(ThisWorkbook.Worksheets("Analytical").Range("A1"), ThisWorkbook.Worksheets("Analytical").Range("A200")) 
    If cell.Value <> "" Then Analytical_userform.ComboBox1.AddItem cell.Value 
Next cell 

Analytical_userform.Show 


End Sub 


Private Sub Client_Button_Click() 

Client_userform.ComboBox1.Clear 

For Each cell In Range(ThisWorkbook.Worksheets("Client").Range("A1"), ThisWorkbook.Worksheets("Client").Range("A200")) 
    If cell.Value <> "" Then Client_userform.ComboBox1.AddItem cell.Value 
Next cell 

Client_userform.Show 


End Sub 

Private Sub Expert_Button_Click() 

Expert_userform.ComboBox1.Clear 

For Each cell In Range(ThisWorkbook.Worksheets("Expert").Range("A1"), ThisWorkbook.Worksheets("Expert").Range("A200")) 
    If cell.Value <> "" Then Expert_userform.ComboBox1.AddItem cell.Value 
Next cell 

Expert_userform.Show 

End Sub 


Private Sub Managerial_Button_Click() 

Managerial_userform.ComboBox1.Clear 

For Each cell In Range(ThisWorkbook.Worksheets("Managerial").Range("A1"), ThisWorkbook.Worksheets("Managerial").Range("A200")) 
    If cell.Value <> "" Then Managerial_userform.ComboBox1.AddItem cell.Value 
Next cell 

Managerial_userform.Show 

End Sub 

Private Sub Project_Button_Click() 

Project_Userform.ComboBox1.Clear 

For Each cell In Range(ThisWorkbook.Worksheets("Project").Range("A1"), ThisWorkbook.Worksheets("Project").Range("A200")) 
    If cell.Value <> "" Then Project_Userform.ComboBox1.AddItem cell.Value 
Next cell 

Project_Userform.Show 

End Sub 

Private Sub Trainer_Button_Click() 

Trainer_userform.ComboBox1.Clear 

For Each cell In Range(ThisWorkbook.Worksheets("Trainer").Range("A1"), ThisWorkbook.Worksheets("Trainer").Range("A200")) 
    If cell.Value <> "" Then Trainer_userform.ComboBox1.AddItem cell.Value 
Next cell 

Trainer_userform.Show 

End Sub 

Private Sub UserForm_Click() 

End Sub 

として追加する必要があり、スナップショットを確認してください:

screenshot screenshot1

私は「読む」をクリックしてトレーニングを開きたいですボタン

関連する問題