+ Reply to Thread
Results 1 to 17 of 17

Code causes Error 1004 then continues

  1. #1
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Code causes Error 1004 then continues

    Hi

    I have some code I have created to set page breaks. Depending on a previous option, my report will be either 3,6,9,12, or 15 pages. The info on each page varies in length, but I use table headers to separate the data onto different pages so none of the tables are split into more than one page.

    My problem when the code gets to a certain line, it gives me error 1004. I will hit "Debug", then I hit continue and the code finishes. I don't understand why I am getting an error on this line, and why I don't have to fix anything to get it to finish running.

    Here is the code:
    Please Login or Register  to view this content.
    I can see the cell its refering to is valid, cell(89,1).
    Any ideas?

    Thanks
    Last edited by davegugg; 09-09-2009 at 05:14 PM.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  2. #2
    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: Code causes Error 1004 then continues

    Pagebreaks are a collection of manual and automatic. You can set manual pagebreaks, but Excel sets automatic ones based on all the things you expect -- paper size, margins, row heights, print area, ...

    You shouldn't be trying to change members of the collection; you should be adding a new one.

    Se Help for the Add method as applied to HPageBreak.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Code causes Error 1004 then continues

    Ok, I tried switching it as follows:

    Please Login or Register  to view this content.
    However, excel puts an extra page break in before my first page break, which creates a page with three lines of data. This is what I was trying to avoid. When I stop and look at the worksheet, it is a dashed-line page break (not sure if that is significant).

    Shouldn't all page breaks disappear when I use ResetAllPageBreaks?

  4. #4
    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: Code causes Error 1004 then continues

    All the manual page breaks go away, and then Excel recalculates the automatic ones.

    Dunno why your workbook prints three rows and then breaks. Post it.

  5. #5
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Code causes Error 1004 then continues

    Ok, here is my original. Use the Print Report Button on Daily Icon Comparison Worksheet. You will notice the code has the error as described in my first post, but then if you hit continue it will finish the sub.
    Last edited by davegugg; 09-08-2009 at 05:26 PM. Reason: Changed workbook name in code

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Code causes Error 1004 then continues

    Here is an example using the other coding as you suggested. For some reason I still get extra page breaks...
    Last edited by davegugg; 09-08-2009 at 05:25 PM.

  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: Code causes Error 1004 then continues

    I can't run that without having the other workbook. The code is still trying to change members of the hpagebreaks collection, rather than clearing the collection and starting from scratch.

    If you post a minimal example (like the print workbook alone) that erroneously breaks after three lines, I'll look at it.

  8. #8
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Code causes Error 1004 then continues

    I have fixed the code. It should not look for other workbooks now.

  9. #9
    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: Code causes Error 1004 then continues

    I don't have a G drive, or a workbook named example1.

  10. #10
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Code causes Error 1004 then continues

    Ok, those are bad examples. I am going to try to create a better one.

  11. #11
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Code causes Error 1004 then continues

    Ok, here is an example. Why aren't the dashed line (auto page breaks) going away as I tell it where I want the page breaks?

    Thanks!
    Attached Files Attached Files

  12. #12
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Code causes Error 1004 then continues

    Quote Originally Posted by shg View Post
    All the manual page breaks go away, and then Excel recalculates the automatic ones.

    Dunno why your workbook prints three rows and then breaks. Post it.
    Is there a way to clear the automatic ones so I can start fresh with no page breaks?

  13. #13
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Code causes Error 1004 then continues

    Because when I use code to add manual page breaks, the automatic ones don't go away. Shouldn't they go away?

  14. #14
    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: Code causes Error 1004 then continues

    There's an automatic page break above line 53, which mean that's all the data Excel can fit on a page. When you set a pagebreak on line 75, it doesn't change the prior fact -- this is clear, right?

    You can reduce the print scaling until the page break appears at or below line 75, and then set manual pagebreaks above the automatic pagebreaks.

  15. #15
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Code causes Error 1004 then continues

    I understand. I think my original problem could be remedied by adding this first:

    Please Login or Register  to view this content.
    To build on what you've said, I added this code. It takes all excel's automatic page breaks and makes them into manual page breaks. Then I can move the location of them to where I want them. This fixes my problem, though after reading your last post I think the better way to do it would be to reduce print scaling then set new page breaks.

    Please Login or Register  to view this content.
    Thanks for all your help shg.

  16. #16
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Code causes Error 1004 then continues

    This can be marked solved, thanks.

  17. #17
    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: Code causes Error 1004 then continues

    You're welcome, post back if you get stuck.

    This can be marked solved, thanks.
    Would you please do the honors?

+ 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