Dan,
UPPER case is for emphasis. I am not yelling. Thanks.
I downloaded your posting and tried it. First of all thanks. BUT it did NOT work for me regarding the
DownloadFile DocumentURL, "D:\TEMP\SaveDocumentHere.Doc" substituting my drive:\path\file name and when using a variable such as DestinationFile.
For the Function I copied it and kept getting a Compile Error for (FileExpress) as variable NOT defined. I then inserted right above that line a Dim statement and it now runs through my loop to try and download some 177 files BUT NO FILES are copied.
Here is my coding: YOUR Function first in a separate Module as listed.
and here is my FULL coding. The files I am trying to download are about 177 files from the United States Coast Guard on Sample Exams they post each year for merchant mariners to sit for their credential exams. NOT ONE is copied and saved on my hard drive in Drive C: or on my Drive Z:. I am using a MAC BOOK PRO running Parallels with Windows 11 on a Virtual Machine.
NOW my program previously use to work BUT a NEWER version of Visual Basic was installed and now many of my macros are giving me problems. This one is a major problem. So far I can fix the others I have encountered.
THANK YOU very much in advance.
rmplant
UPPER case is for emphasis. I am not yelling. Thanks.
I downloaded your posting and tried it. First of all thanks. BUT it did NOT work for me regarding the
DownloadFile DocumentURL, "D:\TEMP\SaveDocumentHere.Doc" substituting my drive:\path\file name and when using a variable such as DestinationFile.
For the Function I copied it and kept getting a Compile Error for (FileExpress) as variable NOT defined. I then inserted right above that line a Dim statement and it now runs through my loop to try and download some 177 files BUT NO FILES are copied.
Here is my coding: YOUR Function first in a separate Module as listed.
VBA Code:
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As LongPtr, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As LongPtr, ByVal lpfnCB As LongPtr) As Long
#Else
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
#End If
Public Function DownloadFile(ByVal URL As String, ByVal DestinationFile As String) As Boolean
' If the API returns ERROR_SUCCESS (0), DownloadFile returns True.
Dim Error_Success As Integer ' My addition which averts the error message.
DownloadFile = (URLDownloadToFile(0&, URL, DestinationFile, &H10, 0&) = CLng(Error_Success))
End Function
and here is my FULL coding. The files I am trying to download are about 177 files from the United States Coast Guard on Sample Exams they post each year for merchant mariners to sit for their credential exams. NOT ONE is copied and saved on my hard drive in Drive C: or on my Drive Z:. I am using a MAC BOOK PRO running Parallels with Windows 11 on a Virtual Machine.
VBA Code:
Sub Download_NMC_And_Copy()
Dim DocumentURL As String
Dim DestinationFile As String
Dim myfile As String
Dim imax, icount As Integer
Dim Error_Success As Integer
Dim myURL As String
' files to Download from NMC for Deck
imax = 178 ' In Column B, starting at Row 2, I have the 178 file names listed that I need to download
icount = 2 ' Because it is Row 2
Application.ScreenUpdating = True
Do While icount <= imax
myfile = Range("B" & icount)
Range("B" & icount).Select ' The URL for the NMC website where the files are stored on the USCG computer is correct.
' I can MANUALLY open the files and then SAVE AS to my hard drive but that takes a lot of time and is a pain.
DocumentURL = "[URL]https://www.dco.uscg.mil/Portals/9/NMC/pdfs/examinations/[/URL]" & myfile ' "q100_ror_inland-international.pdf" is my FIRST file on the NMC website which you might want to replace for "myfile".
DestinationFile = "C:/NMC/2022/" & myfile
DownloadFile DocumentURL, DestinationFile
icount = icount + 1
Loop
End Sub
NOW my program previously use to work BUT a NEWER version of Visual Basic was installed and now many of my macros are giving me problems. This one is a major problem. So far I can fix the others I have encountered.
THANK YOU very much in advance.
rmplant
Last edited by a moderator: