+ Reply to Thread
Results 1 to 7 of 7

Runtime errors

  1. #1
    Registered User
    Join Date
    06-19-2009
    Location
    Edmonton, Alberta
    MS-Off Ver
    Excel 2003
    Posts
    20

    Runtime errors

    Hello I am currently writing a macro that will take one or more files that I choose and will copy them onto a template which will then generate a graph.
    Since the files are saved in different formats I created an if loop that determines which file type it is then calls on the apporpriate subroutine.

    Please Login or Register  to view this content.
    which when i had just a message box in each sub routine it worked fine. Now writing the subroutines I am getting a error inside a the following subroutine.

    Please Login or Register  to view this content.

    now when i hit run/debug i get a run-time error '424': Object required

    on either the line that starts with test_type or location.

    how do i fix this error?

  2. #2
    Registered User
    Join Date
    06-19-2009
    Location
    Edmonton, Alberta
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Runtime errors

    In what line are you referring to?

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Runtime errors

    temp is a local variable in the first routine. If it is to be used in other routines, it must be a module-level variable declared above all other procedures, e.g.,
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    06-19-2009
    Location
    Edmonton, Alberta
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Runtime errors

    I added the line
    Please Login or Register  to view this content.
    in both routines and now get a different run-time error.

    In the same line I now get run-time error '91': Object variable or with block not set.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Runtime errors

    It doesn't do you any good to declare it in the other routine; then both routines have a variable named temp, and they are completely unrelated. You need to declare it outside BOTH routines, and NOT declare it in EITHER.

  6. #6
    Registered User
    Join Date
    06-19-2009
    Location
    Edmonton, Alberta
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Runtime errors

    Thank you very much for your help. As you can tell I am pretty much new to coding let alone vba.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Runtime errors

    You're welcome. If that sorts it for you, would you please mark the thread as Solved?

    You should see VBE Help for Understanding Scope and Visibility

+ 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