+ Reply to Thread
Results 1 to 5 of 5

Run-time error '9'

  1. #1
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    178

    Run-time error '9'

    I APOLOGIZE FOR WASTING YOUR TIME.

    i BELIEVE I FOUND THE PROBLEM.

    Changing the worksheet name without "saving" the excel workbook
    does not update the worksheet name that the vba code sees.

    If I changed a worksheet name AND saved the workbook, then the
    vba code sees the correct worksheet name and the original code worked.

    I apologize to you all,
    bil





    I am getting a Run-time error '9' on line 5 below


    Line 2 Dim ptrWrkBk as Workbook
    Line 3 Dim ptrWrkSht as Worksheet
    Line 4 Set PtrWrkBk = Workbooks(WrkBkName)
    Line 5 Set PtrWrkSht = WorkBooks(WrkBkName).Sheets("FieldData")

    Code on Line 4 works. I Assume code found workbook.
    In Code on line 5 worksheet (sheet1) named "FieldData" exists in the above workbook.
    caps and spelling checked

    Can anyone see what my problem is?
    How do i go about troubleshooting this kind of error?

    Also on a separate note:
    I use the variable, PtrWrkBk, to mean the pointer to workbook X.
    Is this thinking appropriate?
    Last edited by whburling; 05-25-2017 at 03:25 PM. Reason: found solution

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Run-time error '9'

    I assume WrkBkName is open and is not the workbook with the macro in it, otherwise use
    Please Login or Register  to view this content.
    The message boxes should give you the relevant names - if they don't, then it's telling you something
    Instead of
    Please Login or Register  to view this content.
    Try
    Please Login or Register  to view this content.
    then instead of
    Please Login or Register  to view this content.
    use:
    Please Login or Register  to view this content.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    178

    Re: Run-time error '9'

    Kev_

    Thank you for responding.

    In the heading of your reply, you stated: "I assume WrkBkName is open and is not the workbook with the macro in it"

    In fact, the WrkBkName is open and DOES contain the macro. does this make any difference?

    My thinking....and please correct me if you feel I should consider another point of view....is that the excel workbook
    contains worksheets that contain critical input data for the code I wrote in the "macro" part of the workbook. Hence I kept the two together, so to speak. So when I open the workbook, the workbook IS already open. No other workbook is open, but just to be sure, I explicitly defined the workbook by name.


    Otherwise, I would write the code in a blank workbook only containing vba code that i can re-use for other projects.

    I did replace the variables for workbook and sheet names and used direct quotes. no change

    BUT I did try using the index as , in this specific case, the FieldData worksheet has the index of 1. hence Line 5 Set PtrWrkSht = WorkBooks(WrkBkName).Sheets(1) ran WITHOUT RUN TIME ERROR
    I also used your MsgBox PtrWrkSht.name approach and the proper name, FieldData did print out in the MsgBox.


    I would like to understand why my worksheet name, "FieldData" does not work......but at least I know the code on line
    5 is okay with the onlyl problem being the sheet name.

    any more thoughts>
    Last edited by whburling; 05-25-2017 at 03:17 PM. Reason: added feedback

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Run-time error '9'

    Does you sheet name have a trailing space perhaps?
    Run this and count the letters:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Run-time error '9'

    please mark the thread as SOLVED - thread tools, top of thread

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Error message: Run-Time error '1004 '; application-defined or object-defined error
    By Davasu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2015, 06:52 AM
  2. Replies: 1
    Last Post: 10-22-2015, 05:50 AM
  3. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  4. Cannot Publish Excel Pivot Chart - Run Time Error
    By crisb184 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2013, 07:04 AM
  5. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  6. run-time error ;2147023179 (800706b5) time automation error interface unknown
    By karthik72 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-02-2012, 09:31 AM
  7. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM

Tags for this Thread

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