Consulting

Results 1 to 3 of 3

Thread: Run time error 91

  1. #1
    VBAX Regular
    Joined
    Nov 2015
    Posts
    50
    Location

    Run time error 91

    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\", "\\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

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    snb's code will not work with Option Explicit.

    Please insure the code in your post is the code you intended to post.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Nov 2015
    Posts
    50
    Location
    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\", "\\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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •