Excel VBA를 통해 IBM Cognos에서 파일을 다운로드하려고합니다. 스크립트가 실행되지만 열리지 않는 9KB Excel 파일 만받습니다. 이 작업을 어떻게 수행합니까? 인증 헤더를 통해 암호를 전송VBA를 통해 Excel 파일 다운로드
Sub ado_stream()
'add a reference to Microsoft XML v6 and MS ActiveX Data Objects
'via Tools/References
'This assumes the workbook is saved already, and that you want the file in the same folder
Dim fileStream As ADODB.Stream
Dim xmlHTTP As MSXML2.xmlHTTP
Dim strURL As String
strURL = "http://foo.bar"
Set xmlHTTP = New MSXML2.xmlHTTP
xmlHTTP.Open "GET", strURL, False, "username", "password"
xmlHTTP.Send
If xmlHTTP.status <> 200 Then
MsgBox "File not found"
GoTo exitsub
End If
Set fileStream = New ADODB.Stream
With fileStream
.Open
.Type = adTypeBinary
.Write xmlHTTP.responseBody
.Position = 0
.SaveToFile "C:\Users\myname\Downloads\Test.xlsx"
.Close
End With
exitsub:
Set fileStream = Nothing
Set xmlHTTP = Nothing
End Sub
시도는'당신이 스트림을 열기 전에, 당신은 아마 xmlHTTP.ReadyState = 4''를 확인하기 위해 루프를 사용한다 – cyboashu
을 xmlHTTP.responseText' 문서가 완전히로드되었는지 확인하려면 – dbmitch
@cyboashu, .responseBody를 .responseText yeilds로 변경하십시오. "인수가 잘못되었습니다 ..."오류 메시지. – Mateyobi