Results 1 to 6 of 6
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    winNT dir exists - code not seeing the dir (word97 sr2b)

    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

  2. #2
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: winNT dir exists - code not seeing the dir (word97 sr2b)

    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

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: winNT dir exists - code not seeing the dir (word97 sr2b)

    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.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: winNT dir exists - code not seeing the dir (word97 sr2b)

    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

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: winNT dir exists - code not seeing the dir (word97 sr2b)

    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

    Look at all those methods!
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: winNT dir exists - code not seeing the dir (word97 sr2b)

    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

Posting Permissions

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