您好,我希望能够在没有权限的情况下将excel文件复制到文件夹中。
Sub CopyFile()
Dim Folder As String, FileSource As String, FileTarget As String
Folder = "W:\BusIntegration\" & "\"
FileSource = Folder & "excel.xlsx"
FileTarget = "W:\branch\excel.xlsx"
FileCopy FileSource, FileTarget
End Sub
W:\ branch要求具有访问权限。
感谢您的帮助
答案 0 :(得分:0)
权限被拒绝错误通常是文件路径错误,文件正在使用或处于锁定状态的情况。
在您的代码中,select *
into #cartesian_temp
from xsale CROSS JOIN xitem
delete from #cartesian_temp where deptname='books' and itemcolor='bamboo'
select * from #cartesian_temp
变量可能是由于双Folder
引起的错误
\
代替尝试
Folder = "W:\BusIntegration\" & "\"
FileSource = Folder & "excel.xlsx"
'This will return "W:\BusIntegration\\excel.xlsx"
编辑:正如@BigBen所说,如果即使在Windows资源管理器中也根本无法访问该目录,那么您绝对需要拥有访问此目录的权限,然后代码才能起作用
答案 1 :(得分:0)
我过去尝试过以下代码段,并且可在独立计算机上使用-我认为它不能在远程网络上运行...。
'Piece of code to give the script administrator privileges
On Error Resume Next
If Not wScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute wScript.FullName, wScript.ScriptFullName & " /elevate", "", "runas", 1
wScript.Quit
End If
'… your code
On Error Goto 0