获得“权限被拒绝”错误,我做错了什么?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获得“权限被拒绝”错误,我做错了什么?相关的知识,希望对你有一定的参考价值。
我试图在一个包含一堆文件的文件夹中找到一个基于日期名称的特定文件并将其移动到另一个文件夹,听起来很简单吗?好吧,我收到了
没有权限
错误,我不确定我的代码是否错误或是否是文件访问问题。任何帮助,将不胜感激!这是我的代码:
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 "\Rdcicgtcuwd01papp_log36196_WMS" & Wmsn, _
"\olscmesf003gcm_emeaTCU_REPORTSAPPSReportsRegionalWorkflow Management System2017" '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 "\Rdcicgtcuwd01papp_log36196_WMS" & Wmsn, "\olscmesf003gcm_emeaTCU_REPORTSAPPSReportsRegionalWorkflow Management System2017" & myValn & "" & Wmsn2
End Sub
以上是关于获得“权限被拒绝”错误,我做错了什么?的主要内容,如果未能解决你的问题,请参考以下文章