访问对象'_global'的VBA方法'范围'失败错误1004 txt到xls

时间:2018-11-27 10:33:47

标签: excel vba ms-access

我有下面的代码打开一个文本文件,并将其保存为xls,第一次运行,然后出现1004错误,并且没有任何提示,任何想法,TIA

Function Convert_CSV_to_XXX(vInput_File_Name As String, Output_File_Type As String)

Dim XL As Application
Dim XLapp As Excel.Application
Dim vOutput_File_Name As String
Dim vFileFormat As String

vOutput_File_Name = Get_File_Path(vInput_File_Name) & Get_File_Name_Ex_Ext(vInput_File_Name) & "." & Output_File_Type

vFileFormat = xlExcel8

Set XLapp = CreateObject("Excel.Application")

    XLapp.Visible = True
    XLapp.DisplayAlerts = False
    XLapp.Workbooks.Open FileName:=vInput_File_Name, UpdateLinks:=False

    XLapp.ActiveWorkbook.Worksheets("CN03").Columns("A:A").Select
    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
    :="|", 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), Array(11, 2), Array(12 _
    , 2), Array(13, 2), Array(14, 2), Array(15, 2), Array(16, 2), Array(17, 2), Array(18, 2), _
    Array(19, 2), Array(20, 2), Array(21, 2), Array(22, 2), Array(23, 2), Array(24, 2), Array( _
    25, 2), Array(26, 2), Array(27, 2), Array(28, 2), Array(29, 2), Array(30, 2), Array(31, 2), _
    Array(32, 2), Array(33, 2), Array(34, 2), Array(35, 2), Array(36, 2), Array(37, 2), Array( _
    38, 2), Array(39, 2), Array(40, 2), Array(41, 2), Array(42, 2), Array(43, 2), Array(44, 2), _
    Array(45, 2), Array(46, 2), Array(47, 2), Array(48, 2), Array(49, 2), Array(50, 2), Array( _
    51, 2), Array(52, 2)), TrailingMinusNumbers:=True

    XLapp.ActiveWorkbook.SaveAs vOutput_File_Name, FileFormat:=vFileFormat
    XLapp.ActiveWorkbook.Close

    XLapp.Quit

Set XLapp = Nothing

0 个答案:

没有答案