標題:
[發問]
從文字檔存成XLS檔
[打印本頁]
作者:
chiahuo
時間:
2012-12-18 17:45
標題:
從文字檔存成XLS檔
各位大大:
小弟想讓文字檔用VB跑,自動轉成XLS檔,可是在存檔時,出現錯誤,不知要如何修改,有請大大解惑,謝謝。
Sub test()
'
' test 巨集
'
'
Dim fileToOpen
fileToOpen = Application.GetOpenFilename(FileFilter:="Text Files (*.txt),*.txt", Title:="請選擇檔案")
If fileToOpen <> False Then
Workbooks.OpenText Filename:=fileToOpen _
, Origin:=950, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), Array(2, 2), Array( _
3, 2), Array(4, 2), Array(5, 2), Array(6, 2), Array(7, 2), Array(8, 2), Array(9, 2), Array(10 _
, 2)), TrailingMinusNumbers:=True
End If
Set FileFilte = Application.Workbooks
Do
fName = Application.GetSaveAsFilename
Loop Until fName <> False
Workbooks.SaveAs Filename:="Text Files(*.xlsx),*.xlsx,Title:=*.xls") ←這個地方出錯
End Sub
作者:
kimbal
時間:
2012-12-18 22:26
回復
1#
chiahuo
Sub test()
Dim fileToOpen
fileToOpen = Application.GetOpenFilename(FileFilter:="Text Files (*.txt),*.txt", Title:="請選擇檔案")
If fileToOpen <> False Then
Workbooks.OpenText Filename:=fileToOpen _
, Origin:=950, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), Array(2, 2), Array( _
3, 2), Array(4, 2), Array(5, 2), Array(6, 2), Array(7, 2), Array(8, 2), Array(9, 2), Array(10 _
, 2)), TrailingMinusNumbers:=True
End If
Dim wb As Workbook
Set wb = ActiveWorkbook
FileFilter = "Excel Files(*.xls),*.xls"
Do
fName = Application.GetSaveAsFilename(, FileFilter:=FileFilter)
Loop Until fName <> False
wb.SaveAs Filename:=fName, FileFormat:=xlWorkbookNormal
End Sub
複製代碼
作者:
chiahuo
時間:
2012-12-19 09:14
K大你太強了,謝謝你。
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)