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

¦p¦ó¥ÎVBA¶×¤JCSVÀÉ?

¥»©«³Ì«á¥Ñ luhpro ©ó 2011-9-27 23:27 ½s¿è
¦³°ª¤â¥i¥H±Ð§Ú¤@¤U¦p¦ó¥ÎVBA¶×¤JCSVÀÉ©O?ÁÙ¥i¥H¦Û¿ï¦C©M¤À¹jªº²Å¸¹,ÁÂÁÂ~~!
am0251 µoªí©ó 2011-9-3 17:09

¬O©³¤U³o¼Ë¶Ü?
  1. Sub nn()
  2.   Call openCSV("123.txt", 3, 6, " ")
  3. End Sub
½Æ»s¥N½X
  1. Sub openCSV(ByVal sFileName$, lStartLine As Long, lLoadLine As Long, sChar$)
  2.   ' sFileName : CSVÀɮצWºÙ, lStartLine : ¶}©l¦C¸¹, lLoadLine : Ū¨ú¦C¼Æ, sChar : ¤À¹j¦r¤¸
  3.   Dim iI%
  4.   Dim sFullName$, sStr$
  5.   Dim lJ As Long, lPos As Long
  6.   Dim vData
  7.   
  8.   sFullName = ThisWorkbook.Path & "\" & sFileName

  9.   If Dir(sFullName) <> "" Then
  10.     Open sFullName For Input Access Read Shared As #1
  11.       lJ = 1
  12.       Do While lJ < lStartLine
  13.         Line Input #1, sStr
  14.         lJ = lJ + 1
  15.       Loop
  16.       
  17.       For lJ = 1 To lLoadLine
  18.         Line Input #1, sStr
  19.         ReDim vData(0)
  20.         vData = Split(sStr, sChar)
  21. ' ÃD¥~¸Ü : Cells(lJ, 1).Resize(, UBound(vData) + 1) = Application.Transpose(vData) ¦¹¦æµ²ªG¤£¥¿½T¤£ª¾¿ù¦b­þ¸Ì, ¥u¦n§ï¦¨¥H¤U³o¼Ëªº°j°é...
  22.          For iI = 0 To UBound(vData)
  23.            Cells(lJ, iI + 1) = vData(iI)
  24.          Next iI
  25.       Next lJ
  26.     Close (1)
  27.   Else
  28.     MsgBox ("§ä¤£¨ì " & sFileName & " ÀÉ®×")
  29.   End If
  30. End Sub
½Æ»s¥N½X

TOP

¦^´_ 3# am0251
¥i¬O§Ú¥u·Q¶×¤J§Ú·Q­nªº¦æ¼Æ  ³o¼Ëªº°Ýªk,«ÜªÅ¬}ªº Ãø©Ç¨S¤H¦^µª
­nªþ¤W¤å¦rÀÉ: »¡©ú­n·j´Mªº¯S©wªº¦r¦ê? ¦p¦ó ¶×¤J? ¦ó®É°±¤î¶×¤J?

TOP

¥»©«³Ì«á¥Ñ am0251 ©ó 2011-9-6 16:52 ½s¿è

ÁÂÁ¦^´_,¶}±Ò¬O¨S°ÝÃD,¥i¬O§Ú¥u·Q¶×¤J§Ú·Q­nªº¦æ¼Æ,¤S¸Ó«ç»ò¼g©O?
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

¦^´_ 1# am0251

¬O³o­Ó¶Ü?
  1. sub openCSV()

  2. dim mydir as string
  3. mydir = thisworkbook.path & "\"
  4. workbooks.opentext filename:=mydir & 123.txt, datatype:=xldelimited, comma:=true

  5. end sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : µÊ®ð¼L¤Ú¤£¦n¡A¤ß¦a¦A¦n¤]¤£¯àºâ¬O¦n¤H¡C
ªð¦^¦Cªí ¤W¤@¥DÃD