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

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

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

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

¦³°ª¤â¥i¥H±Ð§Ú¤@¤U¦p¦ó¥ÎVBA¶×¤JCSVÀÉ©O?ÁÙ¥i¥H¦Û¿ï¦C©M¤À¹jªº²Å¸¹,ÁÂÁÂ~~!
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

¦^´_ 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

¥»©«³Ì«á¥Ñ 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

¦^´_ 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

¥»©«³Ì«á¥Ñ 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

270710.rar (18.22 KB)
ÁÂÁ¨â¦ìªº¦^ÂÐ,¥u¬Oluhpro¤j¤jªº¼gªk¦³ÂIÃø,¤pªº¨S¬ÝÀ´¦h¤Ö,¨ä¹ê§Ú¥u¬O·Q"¶×¤J"CSV"ÀÉ,¦Ó¤£¬O"¶}±Ò"¦]¬°§Ú­n¿ï¾Ü"¤À¹j²Å¸¹",¦p"TABÁä" "¤À¸¹" "³rÂI" "ªÅ®æ" µ¥¤èªk,ÁÙ¦³´N¬O¶×¤Jªº¦æ¼Æ,¦p³o­ÓÀÉ®×,§Úªº¤À¹j²Å¸¹¬O "³rÂI" ©M "ªÅ®æ",¶×¤Jªº¦æ¼Æ¥u¬O²Ä2¦æ©M²Ä5¦æ,¸Ó«ç»ò¼g©O?
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

¦^´_ 6# am0251
  1. Sub Ex()
  2.     Dim ¶×¥XÀÉ As String, ¶×¤JÀÉ As Workbook
  3.     Set ¶×¤JÀÉ = ActiveWorkbook     'Set ¶×¤JÀÉ = Workbooks("TEST.XLS")
  4.     ¶×¥XÀÉ = "D:\TEST\270710.CSV"
  5.     With Workbooks.Open(¶×¥XÀÉ).Sheets(1)
  6.         .Range("A5").Resize(5).EntireRow.Copy ¶×¤JÀÉ.Sheets(1).[A1]
  7.         '.Range("A5").Resize(5) ->5¦C  ,  EntireRow ¾ã¦C½d³ò
  8.           .Parent.Close False    'Ãö³¬ ¶×¥XÀÉ
  9.     End With
  10. End Sub
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ am0251 ©ó 2011-9-29 13:25 ½s¿è

ÁÂÁ¦^ÂÐ,¥i¯à¬O§Úªí¹Fªº¤£¬O«Ü¦n,³o­ÓÀɮ׬O§Ú¥Î"¸ê®Æ - ±q¤å¦rÀÉ"ªº¤èªk¶×¤Jªº,"SHEET1"¤À¹j²Å¸¹¬O¥Î¤F,"³rÂI" ©M "ªÅ®æ","SHEET2"´N¬O§Ú­nªº¥Øªº¤F,¥u¦³²Ä2©M²Ä5¦æ¶×¤J¤F,§Ú¥u¬O¨S¿ìªk¼g¥X¨Ó........ Inport CSV.rar (122.98 KB)
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

¦^´_ 8# am0251
  1. Sub Ex()
  2.     Dim ¶×¥XÀÉ As String, ¶×¤JÀÉ As Workbook
  3.     Set ¶×¤JÀÉ = ActiveWorkbook
  4.     'Set ¶×¤JÀÉ = Workbooks("TEST.XLS")
  5.     ¶×¥XÀÉ = "D:\TEST\270710.CSV"
  6.     With Workbooks.Open(¶×¥XÀÉ).Sheets(1)
  7.         ¶×¤JÀÉ.Sheets(1).Range("A:A") = .Range("B:B").Value
  8.         ¶×¤JÀÉ.Sheets(1).Range("B:B") = .Range("E:E").Value
  9.         .Parent.Close False    'Ãö³¬ ¶×¥XÀÉ
  10.     End With
  11. End Sub
½Æ»s¥N½X

TOP

ÁÂÁ¦^ÂÐ,¥i¬O§Ú¥Î"¿ý»s"ªº¤èªk±o¨ì¤F¤U­±ªº¥¨¶°,¦³¨S¦³¿ìªk²³æªº¤èªk¼g¥X¨Ó©O?
  1. Sub csv()
  2. '
  3. ' csv Macro
  4. '

  5. '
  6.     With ActiveSheet.QueryTables.ADD(Connection:= _
  7.         "TEXT;E:\Excel\270710.csv", Destination:=Range("$A$1"))
  8.         .Name = "270710"
  9.         .FieldNames = True
  10.         .RowNumbers = False
  11.         .FillAdjacentFormulas = False
  12.         .PreserveFormatting = True
  13.         .RefreshOnFileOpen = False
  14.         .RefreshStyle = xlInsertDeleteCells
  15.         .SavePassword = False
  16.         .SaveData = True
  17.         .AdjustColumnWidth = True
  18.         .RefreshPeriod = 0
  19.         .TextFilePromptOnRefresh = False
  20.         .TextFilePlatform = 950
  21.         .TextFileStartRow = 1
  22.         .TextFileParseType = xlDelimited
  23.         .TextFileTextQualifier = xlTextQualifierDoubleQuote
  24.         .TextFileConsecutiveDelimiter = True
  25.         .TextFileTabDelimiter = True
  26.         .TextFileSemicolonDelimiter = False
  27.         .TextFileCommaDelimiter = True
  28.         .TextFileSpaceDelimiter = True
  29.         .TextFileColumnDataTypes = Array(1, 1, 9, 9, 1, 1, 1)
  30.         .TextFileTrailingMinusNumbers = True
  31.         .Refresh BackgroundQuery:=False
  32.     End With
  33. End Sub
½Æ»s¥N½X
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

        ÀR«ä¦Û¦b : §Ú­Ì­n°µ¦nªÀ·|ªºÀô«O¡A¤]­n°µ¦n¤º¤ßªºÀô«O¡C
ªð¦^¦Cªí ¤W¤@¥DÃD