Consulting

Results 1 to 5 of 5

Thread: Subscript out of range

  1. #1
    VBAX Newbie
    Joined
    Oct 2007
    Posts
    2
    Location

    Subscript out of range

    I'm new to VB, and I was given a program written in VBA within Excel to modify for a new situation. My only (apparent) obstacle is with anything that starts Workbooks. , such as

    Workbooks("BUILDQUIRIES.xls").Activate

    I keep getting a run-time error '9' stating that "subscript is out of range" or run-time error '1004' that your file "could not be found."

    Can someone PLEASE help me?!?

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Check the spelling of the file name or in fact that it exists.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Newbie
    Joined
    Oct 2007
    Posts
    2
    Location

    Subscript out of range

    I already checked the spelling and yes, it exists.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    is it open? It won't be found just because it exists...

    [vba]
    Workbooks.Open Filename:="D:\Desktop\BUILDQUIRIES.xls"
    [/vba]
    adjust the path.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    You might want to add a couple of statements to the Lucas statement to take of the case where the workbook is already open:
    [vba]On Error Resume Next
    Workbooks.Open Filename:="D:\Desktop\BUILDQUERIES.xls"
    On Error GoTo 0[/vba] This would prevent an error interrupt in case the file is already open when you try to open it.

Posting Permissions

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