While running my code to print web pages to PDF there seems to be an issue with the file pathing as the "Run-time error '52'; Bad File name or number " shows but I can't figure out what it is. I confirmed that path name and continue to get the same error. I tried to unlink my OneDrive but there seems to be no change. Also if anyone can help name the files specific things that would be very helpful too. (i.e. first PDF has name General, second L&L, etc.)
Any help is appreciated.
Sub Test2()
Dim i As Long
Dim FileNum As Long
Dim FileData() As Byte
Dim MyFile As String
Dim WHTTP As Object
On Error Resume Next
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
If Err.Number <> 0 Then
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
End If
On Error GoTo 0
If Dir("C:\MyDownloads", vbDirectory) = Empty Then MkDir "C:\MyDownloads"
For i = 1 To 7
MyFile = Cells(i, 1).Text
TempFile = Right(MyFile, InStr(1, StrReverse(MyFile), "/") - 1)
WHTTP.Open "GET", MyFile, False
WHTTP.Send
FileData = WHTTP.ResponseBody
FileNum = FreeFile
Open "C:\MyDownloads\" & TempFile For Binary Access Write As #FileNum
Put #FileNum, 1, FileData
Close #FileNum
Next
Set WHTTP = Nothing
MsgBox "Open the folder [ C:\MyDownloads ] for the downloaded file..."
End Sub
Edit
TempFile is setting incorrectly, assumingly because the URL contains slashes. The cell value is "https://psearch.kitsapgov.com/pdetails/Details?parcel=132501-1-030-1005&page=general" and TempFile is only showing as "Details?parcel=132501-1-030-1005&page=general"