返回列表 上一主題 發帖

如何把EXCEL的儲存格範圍A1:H3000輸出到記事本檔案的 D:\SP20110801.TXT

mystr = Array(x, Application.Text(Date, "yyyymmdd"), .Cells(r, 3), .Cells(r, 4), .Cells(r, 5), .Cells(r, 6), .Cells(r, 8))
改這行

TOP

本帖最後由 metrostar 於 2011-8-3 14:44 編輯

帥哥學長做法是正確的,感恩啦

有點點小問題,日期要當天的年月日日期
像今天是 20110803 , 如果明天是 20110804

TOP

回復 3# metrostar
對不起,我不是帥哥,學長更不敢當,才剛起步學習。
  1. Sub test()
  2. With Sheet1
  3.     For r = 1 To .[A65536].End(xlUp).Row
  4.         If r = 1 Then
  5.             mystr = Array("<TICKER>", "<DTYYYYSSDD>", "<OPEN>", "<HIGH>", "<LOW>", "<CLOSE>", "<VOL>")
  6.         Else
  7.             x = .Cells(r, 1)
  8.             If IsNumeric(x) Then
  9.                 x = .[j1] & Application.Text(x, "0000")
  10.             Else
  11.                 x = [j1] & x
  12.             End If
  13.             mystr = Array(x, "20110802", .Cells(r, 3), .Cells(r, 4), .Cells(r, 5), .Cells(r, 6), .Cells(r, 8))
  14.         End If

  15. Sheet2.Cells(r, 1).Resize(, 7) = mystr
  16. Next
  17. End With
  18. End Sub
複製代碼

TOP

本帖最後由 metrostar 於 2011-8-3 13:33 編輯
回復  metrostar


    結果不知是否正確
chin15 發表於 2011-8-3 08:15


太棒了,可以了
多謝這位帥哥學長
學妹非常感動呢
您真是太強太強了
感謝您並祝賀您
幸福好運永遠降臨您身上

學妹另外一問題,如果不輸出 EXPORT TO TXT , 而把結果輸出 SHEET2呢 , 又要怎麼做呢?
請看新附上的檔案

Book3.rar (8.73 KB)

TOP

回復 1# metrostar


    結果不知是否正確
  1. Sub test()

  2.     Open "d:\SP20110801.txt" For Output As #1
  3.     For r = 1 To [A65536].End(xlUp).Row
  4.         If r = 1 Then
  5.             c = Cells(1, 11).Resize(, 7)

  6.             mystr = Join(Application.Transpose(Application.Transpose(c)), ",")
  7.         Else
  8.             x = Cells(r, 1)
  9.             If IsNumeric(x) Then
  10.                 x = [j1] & Application.Text(x, "0000")
  11.             Else
  12.                 x = [j1] & x
  13.             End If
  14.             mystr = x & "," & "20110801" & "," & Cells(r, 3) & "," & Cells(r, 4) & "," & Cells(r, 5) & "," & Cells(r, 6) & "," & Cells(r, 8)
  15.         End If

  16.         Print #1, mystr
  17.     Next
  18.     Close #1
  19. End Sub
複製代碼

TOP

        靜思自在 : 看別人不順眼,是自己修養不夠。
返回列表 上一主題