Board logo

標題: [發問] 從文字檔存成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
  1. Sub test()
  2.    
  3.    Dim fileToOpen
  4.     fileToOpen = Application.GetOpenFilename(FileFilter:="Text Files (*.txt),*.txt", Title:="請選擇檔案")
  5.     If fileToOpen <> False Then
  6.         Workbooks.OpenText Filename:=fileToOpen _
  7.         , Origin:=950, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
  8.         xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, _
  9.         Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), Array(2, 2), Array( _
  10.         3, 2), Array(4, 2), Array(5, 2), Array(6, 2), Array(7, 2), Array(8, 2), Array(9, 2), Array(10 _
  11.         , 2)), TrailingMinusNumbers:=True
  12.     End If
  13.     Dim wb As Workbook
  14.     Set wb = ActiveWorkbook
  15.     FileFilter = "Excel Files(*.xls),*.xls"
  16. Do
  17.     fName = Application.GetSaveAsFilename(, FileFilter:=FileFilter)
  18. Loop Until fName <> False
  19. wb.SaveAs Filename:=fName, FileFormat:=xlWorkbookNormal
  20. End Sub
複製代碼

作者: chiahuo    時間: 2012-12-19 09:14

K大你太強了,謝謝你。




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)