简体   繁体   English

如何在 vba 的直接窗口中显示目录?

[英]How to show directories in vba's immediate window?

I want to list all directories in c: disk in vba's immediate window,write the below code in immediate window:我想在vba的即时窗口中列出c: disk中的所有目录,在即时窗口中编写以下代码:

Dim FileName As String
FileName = Dir("C:\", vbDirectory)

Do While FileName <> ""
    Debug.Print FileName
    FileName = Dir()
Loop

Now to click enter ,现在点击enter

在此处输入图片说明

How to fix my vba code to show all directories in c: in vba's immediate window?如何修复我的 vba 代码以在 vba 的直接窗口中显示c:中的所有目录?

The immediate window does not execute a script;即时窗口不执行脚本; it runs individual statements, immediately as you hit Enter (whether you just typed the line or not).它会在您按下Enter 键时立即运行单个语句(无论您是否输入了该行)。 You can't script a sequence of such executable statements in that box, the statements must be self-contained.您不能在该框中编写一系列此类可执行语句的脚本,这些语句必须是自包含的。

But you can cheat, by using the : instruction separator :但是你可以通过使用:指令分隔符来作弊:

fn=dir("C:\",vbdirectory):do while fn<>"":?fn:fn=dir:loop

Keep in mind that the window holds no more than 255 lines - you'd have to write to a file to output more than that and be able to view it all.请记住,该窗口不超过 255 行 - 您必须写入一个文件以输出更多内容并能够查看所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM