这样做:
Shell ("C:\Program Files\Internet Explorer\iexplore.exe -embedding http://www.websiteurl.com")
不起作用我需要它,因为我基本上需要它能够重定向并提示用户下载文件.有任何想法吗?
Internet Explorer公开了可以使用的COM可访问接口.如果你真的需要.我建议反对它 - 它相对缓慢,容易出错,繁琐且资源密集.
更优雅地解决您的问题的是使用WinHTTPRequest
.在您的项目中,引用"Microsoft WinHTTP Services,版本5.1",然后继续这样:
Dim HttpRequest As New WinHttp.WinHttpRequest Dim TargetUrl As String Dim TargetFile As String Dim FileNum As Integer TargetFile = "C:\foo.doc" TargetUrl = "http://www.websiteurl.com" HttpRequest.Open Method:="GET", Url:=TargetUrl, Async:=False HttpRequest.Send If HttpRequest.Status = 302 Then TargetUrl = HttpRequest.GetResponseHeader("Location") HttpRequest.Open Method:="GET", Url:=TargetUrl, Async:=False HttpRequest.Send If HttpRequest.Status = "200" Then FileNum = FreeFile Open TargetFile For Binary As #FileNum Put #FileNum, 1, HttpRequest.ResponseBody Close FileNum Debug.Print "Successfully witten " & TargetFile Else Debug.Print "Download failed. Received HTTP status: " & HttpRequest.Status End If Else Debug.Print "Expected Redirect. Received HTTP status: " & HttpRequest.Status End If
硬编码"C:\foo.doc"
当然没有多大意义.我将使用服务器在响应标头中提供的文件名("Content-Type"
或者"Content-Disposition"
,取决于您的期望).