有没有办法通过VBA代码从内部复制Access数据库? 我尝试过使用fso.CopyFile和FileCopy,但由于文件已经打开,它们会导致权限错误。
答案 0 :(得分:2)
我发现你可以使用shell32.dll函数来复制打开的文件。我甚至添加了进度条功能。这是代码
Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Public Const FO_COPY = &H2
Public Const FOF_SIMPLEPROGRESS = &H100
Public Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long
End Type
Public Sub VBCopyFile(ByRef strSource As String, ByRef strTarget As String)
Dim op As SHFILEOPSTRUCT
With op
.wFunc = FO_COPY
.pTo = strTarget
.pFrom = strSource
.fFlags = FOF_SIMPLEPROGRESS
End With
'~~> Perform operation
SHFileOperation op
End Sub
我只需要使用适当的参数调用VBCopyFile Sub并且它有效。