Re: [VBA ] 請問輸出問題
※ 引述《silvaco ()》之銘言:
: Dim FileNo As Integer
: Dim CurrentLine As String
: Dim Filename As String
: Filename = "C:\Documents and Settings\data.txt"
: ' Define file name
: FileNo = FreeFile ' Establish free file handle
: Open Filename For Output As #FileNo ' Open file (writing mode)
: Print #FileNo, "This is a line of text" ' Save line
: Print #FileNo, "This is another line of text" ' Save line
: Close #FileNo ' Close file
: 請問我要如何才能讓data可以變成是一個變數呢??
: 我想用now()函數把每天的檔案存進去~
: 請問可行嗎??該怎麼做呢??
: 請大家指導一下~~謝謝
剛才修改一下
Sub test()
Dim data As Date
Dim d, m, y As String
Dim FileNo As Integer
Dim CurrentLine As String
Dim Filename As String
Worksheets("sheet1").Range("a1").Value = Now()
data = Worksheets("sheet1").Range("a1").Value
d = Day(data)
m = Month(data)
y = Year(data)
Filename = "C:\Documents and Settings\桌面\" & y & m & d & ".txt"
' Define file name
FileNo = FreeFile ' Establish free file handle
Open Filename For Output As #FileNo ' Open file (writing mode)
Print #FileNo, "This is a line of text" ' Save line
Print #FileNo, "This is another line of text" ' Save line
Close #FileNo ' Close file
End Sub
這樣月份存檔會變成只有一個位數
請問有什麼方法可以讓他有2位數嗎??
例如6月是06而不是只有6
請大家指導一下~謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.135.251.190
推
06/17 23:24, , 1F
06/17 23:24, 1F
→
06/17 23:30, , 2F
06/17 23:30, 2F
推
06/17 23:42, , 3F
06/17 23:42, 3F
討論串 (同標題文章)
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章