+ Reply to Thread
Results 1 to 4 of 4

vba runtime error 9

  1. #1
    Registered User
    Join Date
    07-01-2013
    Location
    Hong Kong, China
    MS-Off Ver
    Excel 2003
    Posts
    1

    vba runtime error 9

    I have a code that is running fine on other computers, but get runtime error 9 on my one.

    Here is the code:

    Private Sub cmdLE_Click()

    Workbooks.Open Filename:=("d:\StaffRecord\YearServing.xls")

    With Workbooks("YearServing").Sheets("sheets1")<runtime error 9>

    .Columns("A:A").Select
    Selection.ColumnWidth = 15
    Selection.ShrinkToFit = True
    ~~~
    End With

    I have done a research on error 9 and seems the reason of happening is excel cannot access to the file. However, that is not the problem, the excel can find that file and open it properly.

    When I use the mouse to point to the error statement it shows:
    " Workbooks("YearServing").Sheets("sheets1") = < Subscript out of range > "

    The most strange thing is it only happen on my compter, not others. Is that due to any setting problems or the code?

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: vba runtime error 9

    Maybe it needs the ".xls" ???
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,767

    Re: vba runtime error 9

    Or

    May be something like this...

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: vba runtime error 9

    Try this and see if it changes anything

    Please Login or Register  to view this content.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

+ 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