Adobe Acrobat 无法打开“filename.pdf”,因为它不是受支持的文件类型或因为文件已损坏

问题描述

我的代码当前循环遍历 Excel 中的超链接列表,并将这些链接作为 PDF 批量下载到我桌面上的指定文件夹。

当我在某些网站上使用此代码时,打开 PDF 没有问题。但是,当我在其他网站上尝试并打开下载的文件时,我收到错误消息,“Adobe Acrobat 无法打开‘filename.pdf’,因为它不是受支持文件类型或因为文件已损坏... "

有谁知道我的代码是否有问题或者我该如何解决这个问题?

下面是我的代码

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

Function DownloadFile(URL As String,LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0,URL,LocalFilename,0)
If lngRetVal = 0 Then DownloadFile = True
End Function

Sub DownloadPDFs()
Dim StartRowNum As Long
Dim EndRowNum As Long
Dim pdfname As String
Dim RecordNum As String
Dim URLprefix As String
LastRowPDF = Sheet1.Cells(Rows.Count,"B").End(xlUp).Row
For i = 2 To LastRowPDF
Application.ScreenUpdating = False
URLprefix = Sheet1.Cells(i,2)
RecordNum = Sheet1.Cells(i,3)

pdfname = Environ("UserProfile") & "\Desktop\PDFs\" & RecordNum & ".pdf"

URL = URLprefix
DownloadFile URLprefix,pdfname
Application.ScreenUpdating = True

Next i

End Sub```


Any help would be greatly appreciated,thank you!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)