title: VBA Error on Namespace().CopyHere...and...Namespace().items
body: <p>I'm attempting to modify a VBA script from another post (26486871).</p>
  
  <p>The script will download a Zip file, extract a text file and import the data to Excel.</p>
  
  <p>I don't know VBA so I'll tackle each of the functions one at-a-time.</p>
  
  <ol>
  <li>Create a temp directory with a randomized name................................Complete</li>
  <li>Download a Zip file from a public server...............................................Complete</li>
  <li>Extract the text file (20MB, tab-delimited)..............................................Error</li>
  <li>Import the data into the open worksheet (overwrite the existing data)...Not Yet</li>
  </ol>
  
  <p>On the Extract portion, I'm receiving a run-time error on the following line:</p>
  
  <pre><code>objOApp.Namespace(FileNameToUnzip).CopyHere objOApp.Namespace(varFileNameFolder).items, 256
  </code></pre>
  
  <blockquote>
    <p>"Run-time error '91:  Object variable or With block variable not set."</p>
  </blockquote>
  
  <p>When I hover my cursor over the variables while in Debug Mode, the directory and filenames are correct.
  I'm unsure what is not set.  I appreciate any help.</p>
  
  <pre><code>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") &amp; "\" &amp; RandomString(6) &amp; "\"
  MkDir targetFolder
  targetFileZip = targetFolder &amp; "data.zip"
  targetFileTXT = targetFolder &amp; "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 &amp; UCase(rgch) &amp; "0123456789"
  
  Dim i As Long
  For i = 1 To cb
  RandomString = RandomString &amp; 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
  </code></pre>