+ Reply to Thread
Results 1 to 20 of 20

object not found error

  1. #1
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    object not found error

    I have the following code that, among other things, delete's specific oleobjects if the referenced rows are hidden. The problem is that it gets stuck when it doesn't find an object, whereas I would like it to simply skip ahead in the module. Here's my code:

    Please Login or Register  to view this content.
    Any help will be much appreciated, thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: object not found error

    You need the on error before the line giving you the error
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: object not found error

    Thanks Norie but I don't know how to do it, so can you help me with that? I tried simply moving the line up, but no dice.
    Here's a sample with the code in it:
    Object doesnt exist sample.xlsm

    if you tried this earlier, please download again. the sample was flawed but i fixed it.
    Last edited by Willardio; 12-24-2012 at 03:20 PM.

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

    Re: object not found error

    Hi Willardio,

    Try this:

    Please Login or Register  to view this content.
    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

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: object not found error

    What objects are you actually trying to delete?

    There are none with a name like WDME.

    Also, where is BRNumRGT defined and/or given a value?

  6. #6
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: object not found error

    sorry for the confusion Norie, xladept helped me with this in an earlier thread and there is a sample sheet there:

    http://www.excelforum.com/excel-prog...html?p=3051926

    Plus I got my code all messed up trying to solve this last glitch by myself! I have to go out now but I will clean the code up as best I can tomorrow or the next day and reply to you in this thread again.

    Merry Christmas!

    ~~Willardio~~
    Last edited by Willardio; 12-25-2012 at 12:12 AM.

  7. #7
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: object not found error

    Last edited by Willardio; 12-25-2012 at 02:54 AM.

  8. #8
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: object not found error

    Hi Williardo,

    I was curious about what you were trying to achieve so I have given it a go as well. I have re-written the original routine and have given it a different name. If you want to use this you will have to copy & paste the code below into any module and change the code in the worksheet_change event to call this new routine as opposed to the old routine. I have tested it and thinks it works.

    Please Login or Register  to view this content.
    Hope it works for you
    If you like my contribution click the star icon!

  9. #9
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: object not found error

    Ps. Manually delete existing objects before using the new code because I have slightly changed the name convention.

  10. #10
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: object not found error

    Olaf, your solution (module 'pub_sub_PrepareWorksheet') works perfectly, only it seems to add the boxes three rows too high. at first it was not doing that, so maybe it's something i did? I didn't alter your code, but i did remove three rows on the last page so that the pages will all be the same length. The other thing is that I really need a pagebreak every 43 rows throughout the document, excluding hidden rows (so that the page numbers will show correctly when printing). This is because other macros called "AddPage" (not included in this sample) sometimes are called to add exactly 43 rows (one page) at various points. I added a macro for that (PageBreaks43rows) that might be called from your macro to achieve this.
    Here's the new sample:

    delete excess Oleobjects problem sample Olaf Solution.xlsm

    I was wondering also whether there is a way to do this without the "on error resume" line at the beginning. Perhaps that could be put within the 'Oleobjects.delete' subroutine where it is needed?

    Thanks for all of your help so far. This code runs much faster than my previous code and is looking very promising!

    Best,

    Willardio
    Last edited by Willardio; 12-25-2012 at 02:36 PM.

  11. #11
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: object not found error

    Williardo, I will try to have a look tomorrow otherwise it will be Thursday. Rgds Olaf

  12. #12
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: object not found error

    Thank you Olaf, this has already been my best Christmas present this year! )

  13. #13
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: object not found error

    Hi Willardo,

    I have removed the On Error Resume Next in the main routine (though I am sure it was used properly).

    I have added a new function to check for the existence of an OLE Object with the desired name, and if it cannot be found, ignore that error as a new object will be created anyway. The new function is the only one now that still requires on the On Error Resume Next solution.

    I have run the process a couple of times and the OLE objects get positioned in the correct location (or at least I do not see any problem).

    The page breaks are inserted properly by the code for every report, except for a missing fixed page break for the final page. I have added a line of code for that in the main routine, so that should be solved now as well.

    The code is shown below and I have enclosed the workbook as well.

    Please Login or Register  to view this content.
    delete excess Oleobjects problem sample Olaf Solution revised.xlsm

  14. #14
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: object not found error

    Thank you Olaf. I did lot of testing and found that when I set F19 to 0 or blank, the next time I reset that cell to another number is when the oleobjects jump up three rows. However, if I manually delete the Oleobjects BEFORE setting 0 or blank at F19, the problem doesn't happen. so is there a simple code I can run to delete all Shapes with names starting "WDME*" as a before_change event? With that your original code will work fine.

    Sorry to be a such a nudge, but my users can be even bigger nudges!

    Best,

    Willardio

  15. #15
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: object not found error

    Hi Willardio,

    No problem, if there is a bug, I will fix it. That brings me to the next point, I have tried to do what you do:
    1. enter 5 in F19;
    2. enter 0 in F19;
    3. enter 5 in F19

    and

    1. enter 5 in F19;
    2. enter blanks in F19;
    3. enter 5 in F19

    But in all situations the OLE Objects are created at the correct rows (at steps 1 and 3), and are all removed in step 2. The object are positioned at rows 74, 117, 160, 203 and 246. Are these the correct/desired rows?

  16. #16
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: object not found error

    Hi Willardio, please note that I am testing with the most recent version, the one that I have submitted to you yesterday at 10:02. Have you perhaps made any changes in your version since then?. Something perhaps with the form length? From which report onwards are you seeing a shift of rows? Can you post a copy of the workbook that you are using that shows the error mentioned.

  17. #17
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: object not found error

    This is a new sample based on your first code, not the new one. I will try the new code now.

    delete excess Oleobjects with separate pagebreaks macro and explaination.xlsm

    Thanks,

    Willardio

  18. #18
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: object not found error

    It's the view! as long as i am using Page Break Preview when I run the code the objects place fine. When I run it with the headers and margins showing is when they move up three rows. I will try adding a bit of code to switch views at the beginning and end of your macro to see if that corrects it.

    One other thing: I noticed in the sample you sent the objects are the right size. On my machine I get the propper width but the height is always short. Adjusting .Height or removing the # symbol have no affect here.

  19. #19
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: object not found error

    I added view switching code at the beginning and end, inside the EnableEvents and and it works fine now.

    Please Login or Register  to view this content.
    The only remaining problem is the .Height setting, but the subject of this thread is solved as far as I'm concerned.
    Thanks so much for your help, you have undoubtedly prevented countless incidents of office violence and computer vandalism, and provided me the best christmas present ever!

    Best Regards,

    ``Willardio

  20. #20
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: object not found error

    Willardio, glad to hear. You are welcome

+ 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