PDA

View Full Version : Run time error 91



ChrisAch
08-19-2016, 06:51 AM
Hi all

I have been using the below code for a few months, and always worked fine for me.

All of a sudden it now gives me run time error 91 - 'object variable or with block variable not set'


Sub Open_latest_file()
Application.DisplayAlerts = False
Application.ScreenUpdating = False



'Open the latest Extract file.


sn = Array("\\NetworkExample.All\ (file://\\NetworkExample.All\)", "\\NetworkExample.All\ (file://\\NetworkExample.All\)", "") ' source directory / destination directory

sn(2) = sn(0) & Split(CreateObject("wscript.shell").exec("cmd /c dir """ & sn(0) & "*.zip"" /b/o-d").StdOut.ReadAll, vbCrLf)(0)

With CreateObject("Shell.Application")
.Namespace(sn(1)).CopyHere .Namespace(sn(2)).Items.Item(0)
sn(2) = sn(1) & .Namespace(sn(2)).Items.Item(0)
End With

Workbooks.Open sn(2)

Can anyone see any problems with the above that would cause error 91?

Thank you

SamT
08-19-2016, 08:26 AM
snb's code will not work with Option Explicit.

Please insure the code in your post is the code you intended to post.

ChrisAch
08-19-2016, 08:38 AM
Hi

Yes the below code is intentional and the code that is breaking.


Sub Open_latest_file()
Application.DisplayAlerts = False
Application.ScreenUpdating = False



'Open the latest Wim Extract file.


sn = Array("\\G\All\ (file://\\G\GFX_DFA\All\)", "\\G\All\ (file://\\G\All\)", "") ' source directory / destination directory

sn(2) = sn(0) & Split(CreateObject("wscript.shell").exec("cmd /c dir """ & sn(0) & "*.zip"" /b/o-d").StdOut.ReadAll, vbCrLf)(0)

With CreateObject("Shell.Application")
.Namespace(sn(1)).CopyHere .Namespace(sn(2)).Items.Item(0)
sn(2) = sn(1) & .Namespace(sn(2)).Items.Item(0)
End With

Workbooks.Open sn(2)

I just changed my network names for the purpose of this post.

Thanks.