msoFileDialogFilePicker的延迟绑定



我自学VBA,这可能是最糟糕的一种,我仍然认为自己是个新手。有些事情我就是不能理解,这个网站简直是天赐之物。这个代码不是我自己的,所以我几乎不明白它在做什么,这使得修改变得困难。它在过去的两年里一直有效。该公司现在正在缓慢升级计算机,我们现在有一些运行Office 2010,还有一些运行2013。这意味着我不能再在代码中使用OfficeTool引用,因为它会在系统之间中断。长话短说,我需要对这段代码进行后期绑定,但我不知道如何绑定。我在msoFileDialogFilePicker和msoFileDialogViewList上得到一个错误请溢出社区,救命!

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False 'Select only one file
.Title = "Locate file" 'Set dialog title
.ButtonName = "Choose" 'Set the button caption
.Filters.Clear 'Make sure the filter list is clear
.InitialFileName = "\PUSNBF02commonAdminNew EA's" 'Initial file search location
.InitialView = msoFileDialogViewList 'View as list
'Show the dialog and test the return
If .Show = 0 Then 'didn't pick a file - exit sub
Exit Function
Else
'Should be only one file name - grab it
SourceFile = Trim(.SelectedItems(1))  'Full path of file
strSource = SourceFile
strSourcePath = Left(strSource, InStrRev(strSource, ""))
strSourceFileName = Mid(strSource, InStrRev(strSource, "") + 1)
strSourceExtension = Right(strSource, Len(strSource) - InStrRev(strSource, "."))
'Debug.Print strSourceExtension
End If
End With

只需将它们替换为适当的数字。

您可以通过在即时窗口中键入?msoFileDialogFilePicker来查找这些数字(如果您有早期绑定(,也可以通过在对象浏览器中查找,或者通过普通的谷歌来查找。

msoFileDialogFilePicker的对应编号是3,因此您可以将其替换为:

With Application.FileDialog(3)
'...
.InitialView = 1 'View as list
'...

最新更新