简体   繁体   中英

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:

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

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

Now to click enter ,

在此处输入图片说明

How to fix my vba code to show all directories in c: in vba's immediate window?

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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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