ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¤å¦rÀÉ¥HÂл\©Î¶K¤W¤è¦¡¶×¤JEXCEL«ü©wÄæ¦ì

[µo°Ý] ¤å¦rÀÉ¥HÂл\©Î¶K¤W¤è¦¡¶×¤JEXCEL«ü©wÄæ¦ì

½Ð°Ý­n±N¤å¦rÀɤº®e¶×¤J¦Ü«ü©wÄæ¦ì¤¤¡A¦]«ü©wÄæ¦ì¬Ò¦³¹ïÀ³­pºâ¤½¦¡¡A¬G»Ý­n¥H¶K¤W©ÎÂл\ªº¤è¦¡¶×¤J¦Ó¤£¬O¥H´¡¤J¤è¦¡¶×¤J¸ê®Æ¡]³o¼Ë«áÄò­pºâ¤½¦¡·|¶Ã±¼¡^¡A½Ð°Ý¤U­±¤º®e­n¦p¦ó­×§ï¤~¯à¹F¦¨©O¡H¡H
  1. Sub OpenFile()
  2. Dim strFilt As String
  3. Dim strTitle As String
  4. Dim strFname As Variant
  5. Dim i As Integer
  6. Dim strMsg As String

  7. strFilt = "¤å¦rÀÉ®×,*.txt,"
  8. strTitle = "¥´¶}Excel¤å¥ó"
  9. strFname = Application.GetOpenFilename(FileFilter:=strFilt, Title:=strTitle, MultiSelect:=True)
  10. If Not IsArray(strFname) Then
  11. MsgBox "¨S¿ï¾Ü¤å¥ó¡I"
  12. Else
  13. For i = LBound(strFname) To UBound(strFname)
  14. strMsg = strMsg & strFname(i) & vbCrLf
  15. With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & strFname(i), Destination:=Range("$S$2"))
  16. .Name = "18"
  17. .FieldNames = True
  18. .RowNumbers = False
  19. .FillAdjacentFormulas = False
  20. .PreserveFormatting = True
  21. .RefreshOnFileOpen = False
  22. .RefreshStyle = xlInsertDeleteCells
  23. .SavePassword = False
  24. .SaveData = True
  25. .AdjustColumnWidth = True
  26. .RefreshPeriod = 0
  27. .TextFilePromptOnRefresh = False
  28. .TextFilePlatform = 950
  29. .TextFileStartRow = 1
  30. .TextFileParseType = xlDelimited
  31. .TextFileTextQualifier = xlTextQualifierDoubleQuote
  32. .TextFileConsecutiveDelimiter = False
  33. .TextFileTabDelimiter = True
  34. .TextFileSemicolonDelimiter = False
  35. .TextFileCommaDelimiter = False
  36. .TextFileSpaceDelimiter = False
  37. .TextFileColumnDataTypes = Array(1, 1)
  38. .TextFileFixedColumnWidths = Array(14)
  39. .TextFileTrailingMinusNumbers = True
  40. .Refresh BackgroundQuery:=False
  41. Columns("S:AG").Select
  42. Range("S2").Activate
  43. Selection.ColumnWidth = 3
  44. End With
  45. Next
  46. MsgBox "¿ï¾Üªº¤å¥ó¬O¡G" & vbCrLf & strMsg
  47. End If

  48. End Sub
½Æ»s¥N½X

  1. Sub test()
  2. '¶}±Òtest.txtªºÀÉ®×
  3. Open "c:\temp\test.txt" For Input As #1
  4. i = 1
  5. Do While Not EOF(1)
  6. Input #1, a, b    'Ū¨útest.txtªº¸ê®Æ¡Aµù¡G³o¸Ìªº¸ê®Æ¨C¦æ¥u¦³2­Ó¸ê®Æ¡A©Ò¥H¬O¥u¦³a,b

  7. Range("a1").Offset(i - 1, 0) = a   '±N¸ê®Æ©ñ¨ìa1¶}©l¥H¤U
  8. Range("b1").Offset(i - 1, 0) = b   '±N¸ê®Æ©ñ¨ìb1¶}©l¥H¤U

  9. i = i + 1
  10. Loop

  11. Q:
  12. Close #1    '§âtest.txtÃö±¼¡A³o¸Ì¨SÃöªº¸Ü¡A¤§«á¶}±Ò·|¥X²{¿ù»~
  13. End Sub
½Æ»s¥N½X
°Ê©À¦¨¦]¿n¦]¦¨ªG by huijuang

TOP

        ÀR«ä¦Û¦b : ºÉ¦h¤Ö¥»¥÷¡A´N±o¦h¤Ö¥»¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD