Excel宏可以从命令行将输出直接提取到工作表中吗? [英] Can an Excel macro pull output from a command line directly into a sheet?
问题描述
我有一个VBA宏,它执行命令行功能来创建一个文本文件列出目录中的文件;然而,可以简单地将命令行的putput直接传递到工作表中,而不是将文本文件中的列表复制和粘贴/导入到工作表中?
I have a VBA macro that executes a Command Line function to create a text file listing the files in a directory; however, instead of copying and pasting/importing the list from the text file to the worksheet, is it possible to simply have the putput of the command line be passed directly into the worksheet?
我正在使用的VBA代码现在创建的文件是:
The VBA code I am working with right now to create the file is:
CMD = "DIR /A:-D-H /O:-D-G /B \\directory\* > \\sleuth.txt"
Shell "cmd.exe /c " & CMD
我非常感谢在这方面的任何想法!
I much appreciate any ideas on this front!
推荐答案
You can save it to a string variable using this class. (Direct download link here.)
这里有一个使用示例:
Sub Test()
Dim cls As New clsRunApp
Dim s As String
cls.command = "cmd.exe /k dir"
s = cls.RunAppWait_CaptureOutput
Set cls = Nothing
MsgBox (s)
End Sub
从那里,您可以直接输出到工作表。
From there, you can output it to your worksheet directly.
这篇关于Excel宏可以从命令行将输出直接提取到工作表中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!