打开文件夹中的每个文件并使用 VBA 分隔数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15135637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open every file in a folder and deliminate the data using VBA
提问by Erik
I'm looking for an excel code which can open every file in a folder (the extensions are not the same - they have a date extension) as a text and deliminate it. After I want to work with this tables.
我正在寻找一个 excel 代码,它可以将文件夹中的每个文件(扩展名不一样 - 它们有一个日期扩展名)作为文本打开并对其进行分隔。在我想使用这个表之后。
I actually trying to get some codes from here, but most of them are for xls or without deliminations.
我实际上试图从这里获取一些代码,但其中大部分用于 xls 或不带分隔符。
Can anyone give me a skelet code how could I solve this?
谁能给我一个骨架代码我怎么能解决这个问题?
Thanks
谢谢
回答by evoandy
This code will loop through files in a specified folder (it opens a dialog box to choose folder)
此代码将遍历指定文件夹中的文件(它打开一个对话框来选择文件夹)
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
Hope this gets you started.
希望这能让你开始。