看板 Visual_Basic 關於我們 聯絡資訊
※ 引述《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
fumizuki:format(時間, "yyyymmdd") & .txt 06/17 23:24
silvaco:請問那個時間是必需指定的嗎??我怎麼直接填上去會錯誤呢?? 06/17 23:30
silvaco:oh~ya~終於試出來了~~謝謝大家的指導:) 06/17 23:42