Sub test3() '标准输出-查找相关目录下所有的GIF格式文件。
Dim TS1 As IWshRuntimeLibrary.TextStream
Dim TS2 As IWshRuntimeLibrary.TextStream
Set WShell = New IWshRuntimeLibrary.WshShell
Set WE = WShell.Exec("cmd.exe /k")
Set TS1 = WE.StdIn
TS1.WriteLine Text:="cd /d E:\Chess & Dir *.gif /a /b /s"
TS1.Close
WE.Terminate
Do While WE.Status = WshRunning
DoEvents
Loop
Set TS2 = WE.StdOut
Dim i As Integer
Do Until TS2.AtEndOfStream
i = i + 1
Range("a" & i).Value = TS2.ReadLine
Loop
TS2.Close
End Sub
程序中关于 Dir *.gif /a /b /s的理解,如下表分析可看出,
是找到目录下所有.gif的文件-属性显示-拓展名和文件名。
标签:VBA,Set,ExcelVBA,gif,TextStream,源代码,TS2,IWshRuntimeLibrary,TS1 From: https://www.cnblogs.com/linerning/p/17440426.html