我正在为我的案子寻找解决方案。
我正在为我的部门制作宏,我只是陷入困境。
我有6种不同的职业道路,我想将pdf文档链接到组合框中的值。这就是它的样子。我有一个组合框如下面的截图:
组合框的数据位于隐藏的其他工作表中:
我想要做的是,如果组合框中的值是例如“实践中的自信”,那么在单击命令按钮“读取”之后我想打开B1
列中的pdf文件
有没有办法做到这一点?
答案 0 :(得分:0)
是的,您可以打开文件...以下是如何执行此操作的示例(以及测试代码的子例程)。只需更改下面提到的代码即可。
修改现有按钮单击以添加'OpenFile行,如图所示。 传递FULL路径和文件名。 我假设你的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
答案 1 :(得分: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
请检查快照:
我想点击“阅读”按钮
打开培训