【发布时间】:2019-03-17 08:48:01
【问题描述】:
我在 VBA 中的代码出现了一些问题,下载图像并将其插入到我的 Excel 文档中。
我在循环中有以下代码:
Set theShape = ws.Shapes.AddPicture( _
Filename:=myurl, _
linktofile:=msoFalse, _
savewithdocument:=msoCTrue, _
left:=left, _
top:=top, _
Width:=-1, _
Height:=-1)
其中“myurl”包含指向图像的链接,它可以工作并且下载并插入图像,但每次代码运行时都会打开一个浏览器窗口,并且在手动关闭窗口之前不会继续。
我用以下方式启动 Sub:
With Application
.Cursor = xlWait
.DisplayStatusBar = True
.WindowState = xlMaximized
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
.Interactive = False
.AskToUpdateLinks = False
.IgnoreRemoteRequests = False
End With
浏览器窗口不显示图像,而是显示实际站点的登录信息。该图像无需登录即可访问,并通过 powershell 查看标题我可以看到以下内容:
PS C:\WINDOWS\system32> (wget https://www.deltaco.se/sites/cdn/PublishingImages/Products/hdmi-1022.jpg?width=80).Headers
Key Value
--- -----
SPRequestGuid 1042979e-00c5-c079-20f9-7d4f1f0a2f25
request-id 1042979e-00c5-c079-20f9-7d4f1f0a2f25
X-FRAME-OPTIONS SAMEORIGIN
MicrosoftSharePointTeamServices 15.0.0.4569
X-Content-Type-Options nosniff
X-MS-InvokeApp 1; RequireReadOnly
Access-Control-Allow-Origin *
Accept-Ranges bytes
Content-Length 1669
Cache-Control public, max-age=86400
Content-Type image/jpeg
Date Thu, 11 Oct 2018 07:08:06 GMT
ETag "{73EDFF3E-4289-4D00-A2E8-B3D5C0E3565A},4rend79_1"
Last-Modified Tue, 09 Oct 2018 06:45:17 GMT
Server Microsoft-IIS/8.5
X-AspNet-Version 4.0.30319
X-Powered-By ASP.NET
还有:
PS C:\WINDOWS\system32> wget https://www.deltaco.se/sites/cdn/PublishingImages/Products/hdmi-1022.jpg?width=80
StatusCode : 200
StatusDescription : OK
Content : {255, 216, 255, 224...}
RawContent : HTTP/1.1 200 OK
SPRequestGuid: a942979e-a0b5-c079-20f9-788e9a1abf7c
request-id: a942979e-a0b5-c079-20f9-788e9a1abf7c
X-FRAME-OPTIONS: SAMEORIGIN
MicrosoftSharePointTeamServices: 15.0.0.4569
X-Con...
Headers : {[SPRequestGuid, a942979e-a0b5-c079-20f9-788e9a1abf7c], [request-id, a942979e-a0b5-c079-20f9-788e9a1abf7c], [X-FRAME-OPTIONS, SAMEORIGIN], [MicrosoftSharePointTeamServices, 15.0.0.4569]...}
RawContentLength : 1669
(Powershell 与这个问题无关,只是用它来检查标题)
我看不到代码打开浏览器窗口的任何重定向或其他原因。
我怎样才能完全阻止浏览器窗口打开?
【问题讨论】:
-
我建议先下载文件(到临时文件夹),然后将其插入 Excel。见How do I download a file using VBA (Without internet explorer)