0
嗨我必須編寫一個代碼,我可以輸入我想要的文件擴展名,並將這些擴展名的文件只存入我的excel文件夾包含各種擴展名的文件。 我到目前爲止寫的是用戶可以輸入*,如果他想要所有的文件。但我必須做的是用戶可以輸入.txt/.pdf等,並只拉那些fils.Plz幫助。如何在VB腳本中檢索不同擴展名的文件?
Do while x=0
strAnswer = InputBox("Please enter the file extension * For all files:", _
"File Extension")
If strAnswer = "" Then
MsgBox"You must enter an extension."
Else
a=strAnswer
Exit Do
End If
Loop
If a="*" Then
intRow = 2
'strFileName = "T:\public\Madhumita\New.xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
'objWorkbook.SaveAs(strFileName)
objExcel.Cells(1, 1).Value = "Folder"
objExcel.Cells(1, 2).Value = "File Name"
objStartFolder = "T:\public\Madhumita\Madhu"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
objExcel.Cells(intRow, 1).Value = objfolder.Name
objExcel.Cells(intRow, 2).Value = objFile.Name
intRow = intRow + 1
Next
objExcel.Range("A1:B1").Select
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
Sub SaveAs()
Application.Dialogs(xlDialogSaveAs).Show
End Sub
End If
objExcel.Quit
MsgBox "Done"
您可以使用RegEx進行驗證,以便用戶不能輸入超過4個字符(包括以點開頭)。 –