如何使用今天的日期挑出文件?VB源文件夾問題
我有文件夾中有日期和時間的文件,08-25-2010-123803654.xml,08-25-2010-123804441.xml,08-24-2010-123851240.xml等。
我想拉出今天entrys,當我把我的代碼,它給了我一個錯誤。
我的代碼是:
SourceFolder = 「C:\ TEST(DateTime.Now.tostring( 'MM-DD-YYYY-*')」
林不知道林做錯了
感謝
我的代碼: 模塊模塊1
Private Property fs As Object
Private Property BaseName As Object
Private Property FullTargetPath As Object
Sub Main()
Dim xlApp, xlWkb, SourceFolder, TargetFolder, file
xlApp = CreateObject("excel.application")
fs = CreateObject("Scripting.FileSystemObject")
Const xlNormal = 1
SourceFolder = "C:\TEST\" & DateTime.Now.ToString("MM-dd-yyyy") & "*"
TargetFolder = "C:\TEST\Excel"
'Hide Excel
xlApp.Visible = False
'Process each file in SourceFolder
For Each file In fs.GetFolder(SourceFolder).files
'Open file in SourceFolder
xlWkb = xlApp.Workbooks.Open(file)
'Get Filename
BaseName = fs.getbasename(file)
'Concatenate full path. Extension will be automatically added by Excel
FullTargetPath = TargetFolder & "\" & BaseName
'Save as XLS file into TargetFolder
xlWkb.SaveAs(FullTargetPath, xlNormal)
'Close the file after its done
xlWkb.close()
Next
xlWkb = Nothing
xlApp = Nothing
fs = Nothing
MsgBox("Finished. Bout time!")
End Sub
前端模塊
所以後來sourcefolder應該閱讀, > SourceFolder = directory > TargetFolder =「C:\ TEST \ Excel」 searchpattern如何發揮作用? – GabrielVa 2010-08-25 19:35:13
@gabrielVa:看看我的更新是否能幫助你多一點。 – 2010-08-25 19:57:23
是的,這似乎有幫助很多,我現在明白了,雖然我得到一個新的錯誤,我創建了一個私人函數的目錄(),當我現在運行控制檯應用程序它說以下內容:System.NotImplementedException未處理 消息=該方法或操作未實現。 Source = ConsoleApplication3 – GabrielVa 2010-08-26 11:26:05