johnbrownbaby
New Member
- Joined
- Dec 9, 2015
- Messages
- 38
Hello,
I have this VBA code written in the "ThisWorkbook" section of my excel file to list the filenames from a folder:
I am not able to run the code in excel as the run button does not do anything. It used to work before, however now I am not able to execute the code.
I went into the Trust Center and "Enable VBA macros" but I still cannot execute the code. Please tell me what I am doing wrong.
Thanks!
Please tell me what I am doing wrong.
I have this VBA code written in the "ThisWorkbook" section of my excel file to list the filenames from a folder:
VBA Code:
On Error Resume Next
Const WINDOW_HANDLE = 0
Const BIF_EDITBOX = &H10
Const BIF_NONEWFOLDER = &H200
Const BIF_RETURNONLYFSDIRS = &H1
Set objShell = CreateObject("Shell.Application")
Set wshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'**Browse For Folder To Be Processed
strPrompt = "Please select the folder to process."
intOptions = BIF_RETURNONLYFSDIRS + BIF_NONEWFOLDER + BIF_EDITBOX
strTargetPath = wshShell.SpecialFolders("MyDocuments")
strFolderPath = Browse4Folder(strPrompt, intOptions, strTargetPath)
Set objNewFile = objFSO.CreateTextFile(strFolderPath & "\filelist.txt", True)
Set objFolder = objFSO.GetFolder(strFolderPath)
' CHANGE STARTS HERE :
Set objColFolders = objFolder.Folders
For Each tfolder In objColFolders
objNewFile.WriteLine (tfolder.Name)
Next
' CHANGE DONE.
objNewFile.Close
'**Browse4Folder Function
Function Browse4Folder(strPrompt, intOptions, strRoot)
Dim objFolder, objFolderItem
On Error Resume Next
Set objFolder = objShell.BrowseForFolder(0, strPrompt, intOptions, strRoot)
If (objFolder Is Nothing) Then
Wscript.Quit
End If
Set objFolderItem = objFolder.Self
Browse4Folder = objFolderItem.Path
Set objFolderItem = Nothing
Set objFolder = Nothing
End Function
I am not able to run the code in excel as the run button does not do anything. It used to work before, however now I am not able to execute the code.
I went into the Trust Center and "Enable VBA macros" but I still cannot execute the code. Please tell me what I am doing wrong.
Thanks!
Please tell me what I am doing wrong.