我对如何处理所需的代码有疑问。我一直在搜索过去的3个小时,无法找到一种将代码划分在一起以执行所需功能的方法。这是我想做的事情的概要:
用户运行宏,然后InputBox
弹出窗口,告诉他们输入文件夹名称。从那里,我希望Application.GetOpenFile
(或使用哪个应用程序或dir函数)在指定目录中开始搜索文件夹而不是文件(因为文件夹中可能有多个名称相似的文件),但是将用户带到文件夹,然后用户选择正确的文件打开。然后,一旦选择了文件,将在excel工作表中将其打开。
尝试使用外壳。这是来自用户bburns.km的此问题的函数从VBA中的shell命令捕获输出值?
这与仅列出文件夹和目录的shell命令相结合,可以将您带到需要的地方。
Public Function ShellRun(sCmd As String) As String
'Run a shell command, returning the output as a string'
Dim oShell As Object
Set oShell = CreateObject("WScript.Shell")
'run command'
Dim oExec As Object
Dim oOutput As Object
Set oExec = oShell.Exec(sCmd)
Set oOutput = oExec.StdOut
'handle the results as they are written to and read from the StdOut object'
Dim s As String
Dim sLine As String
While Not oOutput.AtEndOfStream
sLine = oOutput.ReadLine
If sLine <> "" Then s = s & sLine & vbCrLf
Wend
ShellRun = s
End Function
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句