Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

excel - Using WScript with MS Edge to download multiple files leaves open Edge tabs

I am using a Wscript shell to automate the download of multiple (Excel files). The shell command creates a new tab (and popup window) in MS Edge for every download. What I would like is to create a new instance of Edge, and close it when I have finished.

The set-up: I have a third-party company that emails me links with which to download Excel files. If I click on the link in the email, a file is downloaded as a Protected View in Excel. The Excel file is produced by the server on the fly.

To automate this, I have a VBA routine that cycles through a list of these links (which I have separately extracted from my email), and I am using a Wscript shell object to drive Edge.

Code extract:

Dim wsh As New WshShell

Dim strCmd As String
strCmd = "microsoft-edge:"

Dim strLink As String
strLink = "https:\somesite\someserverprocess"    

wsh.Run strCmd & strLink, WaitOnReturn:=True

This code does the job of downloading the file into Excel, but leaves a new tab and a popup window in Edge for each file. Since I will be looping this over multiple files, I will have a lot of tabs and popups left at the end. I am hoping to create a process I can leave to run unattended, so really need to tidy up once this process is finished.

I have read several other questions on this topic on SO (in particular the lack of a COM automation interface for Edge), but without finding an answer. I am open to suggestions. While I am not wedded to Wscript as the method, my preference is to run this process from Excel VBA (as I have to process the actual Excel files as a second step).

question from:https://stackoverflow.com/questions/65924523/using-wscript-with-ms-edge-to-download-multiple-files-leaves-open-edge-tabs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...