• winNT dir exists – code not seeing the dir (word97 sr2b)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » winNT dir exists – code not seeing the dir (word97 sr2b)

    Author
    Topic
    #376596

    Hiya – I have code which checks if a directory exists
    if not then create the directory folder.
    then continue & proceed to perform code.
    please see code below.

    On a small percentage of the pc’s – whats happening is
    although the directory is created on the users C drive – C:TempConvert
    when the function blnFolderExists(strFolderName) runs – its returning a false value
    as then generates a ‘VB runtime error message 91. Object variable or With block variable not set’.

    We have winNT4.0 – do you think this is a windows NT rights issue?
    as its not passing the correct value back to the code?
    Or could it be a word setup ie a reference is missing?
    should I just amend code to perform a workaround?
    tia Diana

    ‘check if folder exists –
    ‘if folder doesnt exist create directory folder & hide folder(so user cant see folder)
    strTempFolder = “C:TempConvert”
    If Not blnFolderExists(strTempFolder) Then
    MkDir strTempFolder
    SetAttr “C:TempConvert”, vbHidden ‘ Set folder with hidden attribute.
    End If

    ”””””””””””””””””””””””””””””””””””””””””””””””
    ‘Function: blnFolderExists(strFolderName) As Boolean
    ‘Purpose: checks if folder exists
    ‘Inputs: pass in name of folder/directory to check.
    ‘Returns: true or false in boolean status – blnFolderExists.
    ”””””””””””””””””””””””””””””””””””””””””””””””
    Function blnFolderExists(strFolderName) As Boolean
    blnFolderExists = CBool(Len(Dir(strFolderName, vbDirectory)))
    End Function

    Viewing 1 reply thread
    Author
    Replies
    • #617494

      Try:

      Dim strTempFolder as String

      strTempFolder = Dir( “C:TempConvert”)

      If strTempFolder = “” Then

      MkDir strTempFolder
      SetAttr “C:TempConvert”, vbHidden ‘ Set folder with hidden attribute.
      End If

    • #617572

      Could the problem be Dir returns false if the folder is hidden?

      If so, your blnFolderExists (looks familiar) will return False
      for any folder that exists but is hidden.

      I’ve since moved to a FSO class module for all folder and file
      access. You might want to look into converting to the FSO objects
      as well. You need a reference to Microsoft Scripting Runtime, but
      that’s really little overhead.

      • #617706

        HI Kevin – does the code look familiar because its yours ?(it was some time ago)
        On most of the pcs- the directory is always hidden – & the code returns true & then continues automation.
        In 1 office- on some of the pcs that the code returns false – once we delete the users NT & local profiles – it works fine.

        However in another office – I’ve noticed that on 1 pc (i just checked the 1 pc)
        that when you go into VBA editor >goto menu Tools>References
        an error message is displayed mentioning that ‘Object library not registered’
        & it doesnt display the Refences Dialog box
        Do you think this could be the cause of the problem?
        If it is – how would you go about installing this – is this from the office97 install cd or would we add/install some .dlls on the pcs?
        would you know which .dlls it would be?

        also
        you mentioned converting to FSO objects.
        I dont know anything about this.
        Its not in the VBA help – how do you find info on references & they functions?
        regards Diana

        • #617828

          I was genuinely unsure if the folder had to be visible for Dir to see it. You confirm that it need not be. Thanks.

          As to the users with local profiles, those users did not have write access to the Temp folder, correct?

          And something is definitely wrong with the Office install on that 1 PC. The object library from which
          Word gets access to the Dir function is “Visual Basic for Applications” — vba332.dll. That’s automatically
          referenced as long as VBA was installed with Office. So, first look for that file on that PC. Should be here:
          (C:Program FilesCommon FilesMicrosoft SharedVBA). If it’s not, reinstall Office on that PC. If it is, try
          registering it again: regsvr32 vba332.dll (from the folder above or name the full path)

          As for an education on the FSO, MSDN is a good place to start:
          http://msdn.microsoft.com/library/default….jFileSystem.asp[/url]

          Look at all those methods!

          • #618362

            Hi Kevin – thanks for that.
            Ive amend the code to the temporary folder Convert so it now has normal attributes.
            as previously the folder Convert had hidden attributes

            ‘check if folder exists -‘if folder doesnt exist create directory folder
            strTempFolder = “C:TempConvert”
            If blnFolderExists(strTempFolder) = False Then
            MkDir strTempFolder
            SetAttr “C:TempConvert”, vbNormal ‘ Set folder with normal attributes.
            Else
            End IF

            & it worked.
            ie on all the new pcs(dells pentium4) that were returning a false value even though the folder did exist with hidden attributes.
            Yes you’re probaly right – its may have something to do with that offices(as in our state branch office) image (ms-office install) for the new pcs.

            Yes look at all those methods – happy reading for me.
            thanks for that Kevin – Diana

    Viewing 1 reply thread
    Reply To: winNT dir exists – code not seeing the dir (word97 sr2b)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: