別のポストからVBAスクリプトを変更しようとしています(26486871)。Namespace()のVBAエラーCopyHere ... and ... Namespace()。items
スクリプトは、Zipファイルをダウンロードしたテキストファイルを抽出し、Excelにデータをインポートします。
私が-時間の関数1のそれぞれに取り組むますので、私はVBAを知りません。
- 無作為化名前で一時ディレクトリを作成します................................完全
- パブリックサーバからZipファイルをダウンロードする.......................................... .....完了
- テキストファイル(20MB、タブ区切り)を抽出してください。.............................. ................エラー
- インポート抽出部にはまだ
オープンワークシートへのデータ(既存のデータを上書き)...、I '再
objOApp.Namespace(FileNameToUnzip).CopyHere objOApp.Namespace(varFileNameFolder).items, 256
「ファイル名を指定して実行時エラー'91::オブジェクト変数またはブロック変数が設定されていないと」次の行に実行時エラーをceiving
デバッグモードでは、ディレクトリとファイル名が正しい間、私は、変数の上に私のカーソルを合わせると。 設定されていないものが不明です。私はどんな助けにも感謝します。
Option Explicit
'Main Procedure
Sub DownloadExtractAndImport()
Dim url As String
Dim targetFolder As String, targetFileZip As String, targetFileTXT As String
Dim wkbAll As Workbook
Dim wkbTemp As Workbook
Dim sDelimiter As String
Dim newSheet As Worksheet
url = "http://www.example.com/data.zip"
targetFolder = Environ("TEMP") & "\" & RandomString(6) & "\"
MkDir targetFolder
targetFileZip = targetFolder & "data.zip"
targetFileTXT = targetFolder & "data.txt"
'1 download file
DownloadFile url, targetFileZip
'2 extract contents
Call UnZip(targetFileZip, targetFolder)
End Sub
Private Sub DownloadFile(myURL As String, target As String)
Dim WinHttpReq As Object
Dim oStream As Object
Set WinHttpReq = CreateObject("Msxml2.ServerXMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.send
myURL = WinHttpReq.responseBody
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile target, 1 ' 1 = no overwrite, 2 = overwrite
oStream.Close
End If
End Sub
Private Function RandomString(cb As Integer) As String
Randomize
Dim rgch As String
rgch = "abcdefghijklmnopqrstuvwxyz"
rgch = rgch & UCase(rgch) & ""
Dim i As Long
For i = 1 To cb
RandomString = RandomString & Mid$(rgch, Int(Rnd() * Len(rgch) + 1), 1)
Next
End Function
Private Function UnZip(PathToUnzipFileTo As Variant, FileNameToUnzip As Variant)
Dim objOApp As Object
Dim varFileNameFolder As Variant
varFileNameFolder = PathToUnzipFileTo
Set objOApp = CreateObject("Shell.Application")
objOApp.Namespace(FileNameToUnzip).CopyHere objOApp.Namespace(varFileNameFolder).items, 256
End Function
[Excelに、ダウンロードし解凍して、インポートのZipファイルにVBA]の可能な重複(http://stackoverflow.com/questions/38571937/vba-to-download-extract-and-import-zip-file – Comintern
[zip形式のcsvをオンラインでホストする方法をExcelにインポートする方法]の複製です(http://stackoverflow.com/questions/26486871/how-to-import-a-zipped-csv-hosted-オンラインからエクセルへ)。新しい質問を掲示する代わりに、あなたの新しい情報で[あなたの古い質問を編集してください](http://stackoverflow.com/posts/38571937/edit)してください。 – Comintern
私はあなたの2番目のコメントの投稿に質問しましたが、それが貢献しなかったので管理者がそれを削除しました。他のポストでは、誰かが自分でコードを書くと言った。私はVBAを知らないので、私は学び、研究しています。 – Bruce