Consulting

Results 1 to 10 of 10

Thread: Directory Issue

  1. #1
    VBAX Regular
    Joined
    May 2015
    Posts
    34
    Location

    Directory Issue

    Hi, Forum looks great!
    Hopefully someone can help with what is probably a very basic question

    I inherited a workbook from a team member who no longer works with me and there are some codes that don't work on my setup.
    When debugging it appears the directory used at creation differs from mine
    This is my location
    C:\Users\jgribbin\Desktop\Walmart ASDA\ScannedDocs
    I can live without the store creation folder but i would like the check store files function to work and to search in the above directory

    My knowledge is limited and until work gets me on the courses i'm pretty much a copy and paste coder. I can uplaod the orginal work book and/or my own tweaked version.

    Thanks in advance for any tips or help received

    John



    ScreenHunter_28 May. 24 22.25.jpg

    Sub createstorefolder()
    
    Dim strFolder As String
    
    
    
    
    
    
        MkDir Range("storefolder") & Range("nameofstore")
    
    
        MsgBox ("Store Folder Created")
    
    
    End Sub
    
    
    Sub checkstorefiles()
    
    
        Range("A16").Select
        
    Do While ActiveCell.Value <> ""
    
    
    DirFile = Range("storefolder") & Range("nameofstore") & "\" & ActiveCell.Value & ".pdf"
    If Dir(DirFile) = "" Then
      ActiveCell.Offset(0, 1).Value = "N"
    Else
        ActiveCell.Offset(0, 1).Value = "Y"
    End If
    
    
        ActiveCell.Offset(1, 0).Select
    
    
    Loop
    
    
    
    
    End Sub

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!

    To build the path to your desktop folder:
    CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator

  3. #3
    VBAX Regular
    Joined
    May 2015
    Posts
    34
    Location
    Quote Originally Posted by Kenneth Hobs View Post
    Welcome to the forum!

    To build the path to your desktop folder:
    CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
    Thanks for the welcome.

    i get

    compile error, invalid outside procedure

    the word desktop highlights

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    welcome to VBAX gribbin.

    did you copy the code Kenneth posted inside a procedure? (Between sub and end sub?)

    https://msdn.microsoft.com/en-us/lib.../gg264268.aspx
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    what does this line return

    Sub Test
        MsgBox CreateObject("WScript.Shell").SpecialFolders("Desktop")
    End Sub
    and is it the same as value in range storefolder?

    if so, does value in range storefolder end with a \ (backslash)?

    this all i can say without seeing the workbook...
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  7. #7
    VBAX Regular
    Joined
    May 2015
    Posts
    34
    Location
    WIS54 Docs 1_4.1.xlsm
    Thanks for helping. I have attached my workbook

    ScreenHunter_30 May. 25 09.29.jpg

  8. #8
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    welcome.


    so they are not the same.

    afaik, starting from Windows Vista, the default location for special folders such as desktop is Users. i think the workbook you posted is created in Windows XP since Documents and Settings is used.

    the value is C:\Documents and Settings\jgribbin\Desktop\ASDA Stores\
    what you need is C:\Users\jgribbin\Desktop\ASDA Stores\

    try changing Documents and Settings to Users in R5.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  9. #9
    VBAX Regular
    Joined
    May 2015
    Posts
    34
    Location
    Perfect, Simple when you know how.

    Thank you very much

  10. #10
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are welcome.

    if the new folders and files will be on your desktop i would use something like this.

    Sub createstorefolder()
        Dim strFolder As String
            
        strFolder = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\" & "ASDA Stores\" & Range("nameofstore")
        
        MkDir strFolder
        
        MsgBox ("Store Folder Created")
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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