我正在使用下面列出的脚本(我老实地从这个网站上偷走了这个)来获取表单上的浏览按钮。任务只是启动MS文件对话框,以便可以选择文件(在本例中为图像文件)。选择记录并单击“确定”后,将文件名和位置粘贴到字段中。 查看表格时,文件名和位置就像应该粘贴一样。问题出在我建立的报告中。我有一个图像集显示与控制源链接回该文件地址字段。但它不会显示图像 但是,如果我手动为字符键入相同的地址字符,甚至“复制”,删除,然后将相同的条目“粘贴”到字段中,则图像在报告上显示正常。 我已经检查过以确保在任何地方都没有空格或字符。我在这里不知所措。 任何帮助将不胜感激,我很乐意给你我的第一个出生。好吧也许不是第一个我喜欢他,但你可以拥有第二个,她是地狱。
Private Sub Command67_Click()
On Error GoTo SubError
'Add "Microsoft Office 14.0 Object Library" in references
Const msoFileDialogFilePicker As Long = 3
'Dim FD As Office.FileDialog
Dim FDialog As Object
Dim varfile As Variant
Set FDialog = Application.FileDialog(msoFileDialogFilePicker)
EmployeePicture = ""
' Set up the File Dialog
Set FDialog = Application.FileDialog(msoFileDialogFilePicker)
With FDialog
.Title = "Choose the spreadsheet you would like to import"
.AllowMultiSelect = False
.InitialFileName = "C:\Users\" 'Folder picker needs trailing slash
.Filters.Clear
.Filters.Add "All", "*.*"
If .Show = True Then
If .SelectedItems.Count = 0 Then
'User clicked open but didn't select a file
GoTo SubExit
End If
'An option for MultiSelect = False
'varFile = .SelectedItems(1)
'EmployeePicture = varFile
'Needed when MultiSelect = True
For Each varfile In .SelectedItems
EmployeePicture = EmployeePicture & varfile & vbCrLf
Next
Else
'user cancelled dialog without choosing!
'Do you need to react?
End If
End With
SubExit:
On Error Resume Next
Set FDialog = Nothing
Exit Sub
SubError:
MsgBox "Error Number: " & Err.Number & " = " & Err.Description, vbCritical + vbOKOnly, _
"An error occurred"
GoTo SubExit
End Sub