我试图在一个包含一堆文件的文件夹中找到一个基于日期名称的特定文件并将其移动到另一个文件夹,听起来很简单吗?好吧,我收到了
没有权限
错误,我不确定我的代码是否错误或是否是文件访问问题。任何帮助,将不胜感激!这是我的代码:
Sub MoveFiles()
Dim myValn As String
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim myDate3 As String
Dim Wmsn As String
Set ws = ThisWorkbook.Worksheets("UPLOADER")
Set ws2 = ThisWorkbook.Worksheets("VARIABLES")
myName = ws2.Range("B2").Value
myValn = ws2.Range("B1").Value
myDate3 = Format(Date, "mm-dd-yyyy")
Wmsn = "WMS_36196_PROD_" & myDate3 & ".csv" 'trying to find the file to move with the current date in it's name
'example filename is WMS_36196_PROD_12-21-2017.csv
'source path below
FileCopy "\\Rdcicgtcuwd01p\app_log\36196_WMS\" & Wmsn, _
"\\olscmesf003\gcm_emea\TCU_REPORTS\APPS\Reports\Regional\Workflow Management System\2017\" 'destination path
End Sub
我已根据@Alex K的有用建议修改了代码,现在它完美地运行了。问题是,我没有为目的地指定文件名,仅针对原点。谢谢你的解决!
正确的代码是这样的:
Sub WMS()
Dim myValn As String
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim myDate3 As String
Dim Wmsn As String
Dim Wmsn2 As String
Set ws = ThisWorkbook.Worksheets("UPLOADER")
Set ws2 = ThisWorkbook.Worksheets("VARIABLES")
myName = ws2.Range("B2").Value
myValn = ws2.Range("B1").Value
myDate3 = Format(Date, "mm-dd-yyyy")
Wmsn = "WMS_36196_PROD_" & myDate3 & ".csv"
Wmsn2 = "36196_WMS_" & myDate3 & ".csv"
'source path below
FileCopy "\\Rdcicgtcuwd01p\app_log\36196_WMS\" & Wmsn, "\\olscmesf003\gcm_emea\TCU_REPORTS\APPS\Reports\Regional\Workflow Management System\2017\" & myValn & "\" & Wmsn2
End Sub