I am trying a VBA script for my job and at the end I would like it to back itself up by copying all the files to a network drive. This would take a very long time as its a lot of data and the VPN is slow.
Rather than writing my own progress bar script to let the user know it's still working can VBA just call the normal [Windows File Transfer Popup][1] to track this?
Here is the code I currently have however when I run it from a workbook it crashes the workbook without copying anything.
#If VBA7 Then ' VBA7
Public Declare PtrSafe Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As LongPtr
Public Const FO_COPY = &H2
Public Const FOF_SIMPLEPROGRESS = &H100
Public Const FOF_NOCONFIRMATION As Long = &H10
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
#End If
Public Sub VBCopyFolder(ByRef strSource As String, ByRef strTarget As String)
Dim op As SHFILEOPSTRUCT
With op
.wFunc = FO_COPY
.pTo = strTarget
.pFrom = strSource
.fFlags = FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION
End With
'~~> Perform operation
SHFileOperation op
End Sub
Sub copy_stuff()
Call VBCopyFolder("C:\Users\tihall\Daily Reports\V2 Testing\src", "C:\Users\tihall\Daily Reports\V2 Testing\dst")
End Sub