0

I wrote the following code to import TXT files in a ZIP file to excel. To do this I have to be able to unzip the file first.

I use:

ShellApp = CreateObject("Shell.Application")
ShellApp.Namespace(unzipToPath).CopyHere 
ShellApp.Namespace(Filename).items

to do so but it keeps returning

error 91

The namespace contains Filename as a variable because I am looping through a list of file names in my workbook.

I hope this discription is clear and you guys are able and willing to help me out. If you guys needs any additional information please let me know.

Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
J2015
  • 1
  • 1
  • Do you have `Option Explicit` specified at the top of the module? Is `hellApp` a typo in the post or in your code? – Mathieu Guindon Feb 23 '18 at 15:09
  • Yes I have option explicit specified, but it stil returns error 91. I don't see hellapp in the code, must be a typo. – J2015 Feb 27 '18 at 09:02
  • it returns the error 91 at the namespace line – J2015 Feb 27 '18 at 09:10
  • According to MSDN documentation, if Namespace method fails, the return value is a nothing and therefore we can get seemingly unrelated error 91 “With or object variable not set”. – J2015 Feb 27 '18 at 09:42
  • It's absolutely related... read up on object variables and the `Set` keyword, and split up your instructions so that 1 line of code contains 1 instruction. That way you can have your code conditionally handle a failure instead of assuming a success. – Mathieu Guindon Feb 27 '18 at 12:28
  • So `ShellApp.Namespace` is failing. Give it a valid argument? Also what I meant was that you need `Set unzipNamespace = ShellApp.Namespace(unzipToPath)` and *then* `If Not unzipNamespace Is Nothing Then unzipNamespace.CopyHere`, and maybe an `Else` to handle the failed `Namespace` call, e.g. `MsgBox "Unable to get namespace for '" & unzipToPath & "'. Verify inputs & try again."` – Mathieu Guindon Feb 27 '18 at 15:12

0 Answers0