-1

我正在寻找一个 excel 代码,它可以将文件夹中的每个文件(扩展名不同 - 它们具有日期扩展名)作为文本打开并分隔它。在我想使用这些表之后。

我实际上试图从这里获取一些代码,但其中大多数是用于 xls 或没有分隔符的。

谁能给我一个骨架代码我怎么能解决这个问题?

谢谢

4

1 回答 1

0

此代码将遍历指定文件夹中的文件(它会打开一个对话框来选择文件夹)

Dim sPath As String
Dim sFil As String
Dim FolderPath As String
   Dim diaFolder As FileDialog

   ' Open the file dialog
   Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
    diaFolder.AllowMultiSelect = False
    diaFolder.Show
    FolderPath = diaFolder.SelectedItems(1)

     ' Cycle through spreadsheets in selected folder

sPath = FolderPath & "\" 'location of files

sFil = Dir(sPath & "*.xls") 'change or add formats
Do While sFil <> "" 'will start LOOP until all files in folder sPath have been looped            through


Set oWbk = Workbooks.Open(sPath & "\" & sFil) 'opens the file
' do something

oWbk.Close True
sFil = Dir

Loop

希望这能让你开始。

于 2013-02-28T12:47:43.670 回答