2017-08-31 121 views
0

我正在使用VBA代码将TEXT文件从文件夹导入excel工作簿。 我的文本文件中包含非英文编码/起源,我要导入的文件,1253希腊Windows编码,但无法弄清楚如何添加origin:="1253"(如果我右)在此代码:将文本文件导入excel时使用VBA设置文件来源

Sub LoadPipeDelimitedFiles() 
'UpdatebyKutoolsforExcel20151214 
    Dim xStrPath As String 
    Dim xFileDialog As FileDialog 
    Dim xFile As String 
    Dim xCount As Long 
    On Error GoTo ErrHandler 
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker) 
    xFileDialog.AllowMultiSelect = False 
    xFileDialog.Title = "Select a folder [Kutools for Excel]" 
    If xFileDialog.Show = -1 Then 
     xStrPath = xFileDialog.SelectedItems(1) 
    End If 
    If xStrPath = "" Then Exit Sub 
    Application.ScreenUpdating = False 
    xFile = Dir(xStrPath & "\*.txt") 
    Do While xFile <> "" 
     xCount = xCount + 1 
     Sheets(xCount).Select 
     With ActiveSheet.QueryTables.Add(Connection:="TEXT;" _ 
      & xStrPath & "\" & xFile, Destination:=Range("A1")) 
      .Name = "a" & xCount 
      .FieldNames = True 
      .RowNumbers = False 
      .FillAdjacentFormulas = False 
      .PreserveFormatting = True 
      .RefreshOnFileOpen = False 
      .RefreshStyle = xlInsertDeleteCells 
      .SavePassword = False 
      .SaveData = True 
      .AdjustColumnWidth = True 
      .RefreshPeriod = 0 
      .TextFilePromptOnRefresh = False 
      .TextFilePlatform = 437 
      .TextFileStartRow = 1 
      .TextFileParseType = xlDelimited 
      .TextFileTextQualifier = xlTextQualifierDoubleQuote 
      .TextFileConsecutiveDelimiter = False 
      .TextFileTabDelimiter = False 
      .TextFileSemicolonDelimiter = False 
      .TextFileCommaDelimiter = False 
      .TextFileSpaceDelimiter = False 
      .TextFileOtherDelimiter = "|" 
      .TextFileColumnDataTypes = Array(1, 1, 1) 
      .TextFileTrailingMinusNumbers = True 
      .Refresh BackgroundQuery:=False 
      xFile = Dir 
     End With 
    Loop 
    Application.ScreenUpdating = True 
    Exit Sub 
ErrHandler: 
    MsgBox "no files txt", , "Kutools for Excel" 
End Sub 

回答

0

我想我是在急... 这里是答案:

.TextFilePlatform = 1253 
相关问题