
我正在使用 VBA 腳本儲存標題為“月-日-時-分”在名為的資料夾內“月年”
不管怎樣,excel不喜歡我的程式碼,
ActiveWorkbook.SaveAs "C:\Users\" & Environ$("UserName") & _
"\Documents\Workout Logs\" & _
Format$(Date, "mmmm-yyyy") & _
"\" & _
Format$(Date, "mmmm-dd") & Format$(Time, "hh-mm") & ".xls"
具體這部分
"\" & _
我如何以牠喜歡的方式表達路徑中的 \ 中斷,以便它看到
Format$(Date, "mmmm-yyyy") & _
作為將保存文件的資料夾
Format$(Date, "mmmm-dd") & Format$(Time, "hh-mm") & ".xls"
應該放在?
答案1
這在我的電腦上運作良好(Windows Excel 2013)
Sub test()
a = "C:\Users\" & Environ$("UserName") & _
"\Documents\Workout Logs\" & _
Format$(Date, "mmmm-yyyy") & _
"\" & _
Format$(Date, "mmmm-dd") & Format$(Time, "hh-mm") & ".xls"
MsgBox (a)
End Sub
訊息框結果C:\Users\username\Documents\Workout Logs\May-2016\May-1910-13.xls
它的作用是一樣的,只是將字串保存到變數而不是保存文件。