+ Reply to Thread
Results 1 to 10 of 10

Moved workbooks to folders now User form "Subsript out of range"

Hybrid View

cheelie Moved workbooks to folders... 05-19-2008, 06:24 AM
royUK Your code expects the files... 05-19-2008, 06:34 AM
cheelie Hi Roy Thanks for your... 05-19-2008, 06:56 AM
royUK Have you change the... 05-19-2008, 07:19 AM
cheelie Hi Roy No not changed this... 05-19-2008, 07:24 AM
davesexcel Could be this ... 05-19-2008, 06:53 AM
  1. #1
    Registered User
    Join Date
    06-25-2007
    Posts
    35

    Moved workbooks to folders now User form "Subsript out of range"

    Hi Guys
    I'm sure this must be an easy fix and I'm sure I'll look like a fool once It's resolved!
    The attached workbook has a userform which was searching the same folder where this file is located for entries in columns "A" and "B" of files named in column "I" (workbook1, workbook2 etc).
    I have this placed on a sharepoint and want to move the files into specific folders (folder1/workbook1, folder2/workbook2 etc.) so I can set them as view only folders to stop unuathorised editing.
    I am now getting a "Subscript out of range" error after doing a search. I can see it's a problem with the file name as it's pulling it from text in a cell but can't work out a fix!

    Thanks!!
    Attached Files Attached Files

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Your code expects the files to be in the same folder as the maon workbook, see

     Workbooks.Open ThisWorkbook.Path & "/" & c.Value & ".xls"
    You need to change ThisWorkbook.Path
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-25-2007
    Posts
    35
    Hi Roy

    Thanks for your reply.
    The workbooks open method seems to work Ok as the I've changed the cell value it's referencing to reflect the new path....from workbook1 ".xls" to folder1\workbook1 ".xls"; it seems to screw up here:

    Set ws = Workbooks(c.Value & ".xls").Worksheets(1)
    Thanks

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Have you change the ThisWorkBook part in the code?

  5. #5
    Registered User
    Join Date
    06-25-2007
    Posts
    35
    Hi Roy

    No not changed this workbook path...am a little confused!!
    This is on a sharepoint and as the codes stands I can see a dialogue box open and it is openeing the file from within the new folder with the new path name visible....this is why I assumed this part of the code was OK!!

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Have you tried Dave's amended code?

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525
    Could be this

             Workbooks.Open ThisWorkbook.Path & "/" & c.Value & ".xls"
    Should be something like this?
             Workbooks.Open "C:\Documents and Settings\Charlotte\My Documents\Admin\Payroll\Time Sheets\" & "/" & c.Value & ".xls"'
    What I do is use windows explorer, that shows the folder address, then copy and paste it into the code

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1