Problem Creating a usable zip file using VBA. Does anyone have an alternative?
I am hitting a problem creating a usable zip file using VBA.
I am using the following code block to create a zip file. I found it in virtually all internet posts that I came across and for that, I copied it with high confidence that it will work. But it's not working as expected when the storage device is a MicroSD or Flash Drive. the sub-routine works fine if the storage device is an internal hard drive, portable hard drive (HDD) or portable solid-state drive (SSD)
sub Create_Zip_File (argDestZipPath as Variant)
Open argDestZipPath For Output As #1 'Create an empty zip file
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
end sub
The sub-routine does create an empty zip file on a Flash Drive or MicroSD storage device on the specified path, but I can't open it either manually or with vba code. I get the following prompt as I manually click on the zip file icon in the window or as I attempt to utilize the shell.CopyHere method using the statements below.
Set ShellApp = CreateObject("Shell.Application")
ShellApp.Namespace(argDestZipPath).CopyHere ShellApp.Namespace(argItemToZipPath)
In comparison, I can manually create an empty zip file in the same location on the Flash or MicroSD and can successfully open the resulting file by manually clicking the icon or by way of vba code without incurring the prompt. I can also create the empty zipped file on the hard drive, then move it to the flash drive or MicroSD where it works normally without incurring the prompt. The problem occurs only when the subroutine creates the zip file directly to the FlashDrive or MicroSD.
Background
I am using Windows 10 (Home), with the most recent updates, and am using MS Access in an Office 365 subscription that I believe is also up to date. I have a 64bit machine. The MicroSD card and flash drive are formatted as NTFS.
I suspect there is an alternative to the Print statement that creates the zip file that will configure the zipped file exactly as does the manual procedure available on the windows explorer shortcut menu
Does anyone know an alternative to the following?
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
My current vba workaround is to automatically create the empty zip file on the hard drive, then move copy (via FileSystemObject class) a pre-existing empty zipfile.zip on the hard drive to the MicroSD or Flash drive, then renaming it according to characteristics of the intended content before proceeding to send files to it. This is effective as a stop-gap but certainly not preferred.