locked
error 91 object variable or with block variable not set RRS feed

  • Question

  • i have this code, it worked fine on my old computer, not it doesn't work any more, why ? something to do with excel 2016 of with references ?

    Private Sub CommandButton1_Click()
    Dim sFile As Variant
    Dim i, j, im, it, il, kolom, lijn, aantall, aantalp   As Integer
    Dim naam As String
        Dim lastrow As Long
    Dim nieuwbestand As String
     Dim bestand As String
    Dim Response As Integer
    Dim oShell: Set oShell = CreateObject("Shell.Application")
    Dim oDir:   Set oDir = oShell.Namespace("C:\Users\User01\Documents\images\" & Cells(2, 2) & "\")
    Dim teller As Integer
        Response = MsgBox("th en med bestanden aanmaken ?  j / n ?", vbYesNo)
     
     If Response = vbYes Then

    For Each sFile In oDir.Items -------> this line gives the error 91
     If oDir.GetDetailsOf(sFile, 11) = "Picture" Or oDir.GetDetailsOf(sFile, 11) = "Afbeelding" Then
    naam = oDir.GetDetailsOf(sFile, 0)
     bestand = "C:\Users\User01\Documents\images\" & Cells(2, 2) & "\" & naam
     
                nieuwbestand = "C:\Users\User01\Documents\images\" & Cells(2, 2) & "\" & "med_" & naam
                Call WIA_ResizeImage(bestand, nieuwbestand, 800, 800)
               
                nieuwbestand = "C:\Users\User01\Documents\images\" & Cells(2, 2) & "\" & "th_" & naam
               
             '   If oDir.GetDetailsOf(sFile, 169) > oDir.GetDetailsOf(sFile, 171) Then
                     Call WIA_ResizeImage(bestand, nieuwbestand, 400, 400)
                 '   Else
                    
                  '  Call WIA_ResizeImage(bestand, nieuwbestand, 400, 400)
                  '  End If
               
                naam = oDir.GetDetailsOf(sFile, 0)
               
               
         End If
        Next

    Monday, January 15, 2018 8:34 PM

Answers

  • Hi tekoko10,

    I try to make a test with your code.

    i find that the value of 'oDir' is nothing and this caused the error in loop.

    you will notice that you are appending the value of a cell. that raise this issue.

    if we remove it then you will notice that 'oDir' get value properly.

    so to solve the issue , you need to properly set the value of oDir.

    you can see that oDir is not a type of string. so you cannot append the value to it like string.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, January 16, 2018 5:05 AM

All replies

  • Hi tekoko10,

    I try to make a test with your code.

    i find that the value of 'oDir' is nothing and this caused the error in loop.

    you will notice that you are appending the value of a cell. that raise this issue.

    if we remove it then you will notice that 'oDir' get value properly.

    so to solve the issue , you need to properly set the value of oDir.

    you can see that oDir is not a type of string. so you cannot append the value to it like string.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, January 16, 2018 5:05 AM
  • thanks very much ,

    in the meantime i did find it myself . it was rather stupid of me, i reorganized my folders and so the name of the folder was incorrect. i looked through everything , except that ..... terrible  !

    Tuesday, January 16, 2018 10:54 AM