+ Reply to Thread
Results 1 to 17 of 17

Format tab for printing

  1. #1
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Format tab for printing

    I have a macro that copies a tab with formulas and pastes values/formats/column widths to replicate it in another workbook without formulas. However, I need to get the new tab into a print-ready format but the coding I have right now is not doing the trick.

    There are only two columns that need to be printed and currently there is a page break after the first column, however, I need it to be after the second. The original tab is already formatted this way, but the print format is not being carried over in the "paste special > formats" process. Also, after checking the results of the code I am using, it seems that nothing changes. What am I doing wrong here?

    Thanks!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Format tab for printing

    Hello ATLGator,

    You will get an answer sooner if you post a copy of the workbook. A lot of time can be wasted going back and forth trying to guess what you have done and how you did it.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Format tab for printing

    Here is a sample file. If you step into the Macro, it stops when you hit the page formatting.
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Format tab for printing

    Hello ATLGator,

    I refined your macro. Try this version and let me know the results on your nd.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Format tab for printing

    Leith, the results of your code copied the entire tab into a new workbook, formulas and all. However, I am trying to just copy the selection and paste the values, widths, and formats instead of the formulas. Also, I don't want to have the macro button show up in the new workbook. Is there a way to just fix the page break by moving the break to after column B instead of after column A?

    Thanks

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Format tab for printing

    Hello ATLGator,

    I am puzzled by that problem. Everything I tried failed to correct it or created another problem. It could be on my end because my computer has been a little unstable today.

    The page break views are not the same on my computer once the sheet was copied using the original code. The only way I could get the same result was to copy the entire sheet. I can add additional code to clean up the sheet - formulas, remove the button, etc. It isn't clear to me why the page break appears in column "A", even after setting the margins the same as the original worksheet.

    Attempting to move the page break via code on my computer resulted in an error. Not sure if you are experiencing that problem also. Let me know what problems you're having then I will know how much of what I'm experiencing is due to my computer.

  7. #7
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Format tab for printing

    When I first put the code together, I wasn't getting an error - just nothing was changing. Then, I closed the workbook and re-opened it, and now I am getting an error: "Run-time error '1004': Application-defined or object-defined error"

  8. #8
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Format tab for printing

    I just tried ActiveSheet.PageSetup.PrintArea = "$A$1:$B$18" instead of ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=2 but that didn't work either

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Format tab for printing

    Hello ATLGator,

    I will add the additional code to macro to clean the sheet. It doesn't look like there is any other choice.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Format tab for printing

    Hello ATLGator,

    Here is the macro with the extra code. It looks good on my end but let me know how it works for you.
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Format tab for printing

    Leith, I appreciate the help but it doesn't really accomplish my goal. I am tying to get the new workbook to:
    - have only one tab, named based on what is put in by the user in the original workbook
    - name the file based on what is put in by the user in the original workbook
    - have the new workbook be a visual replica of the original, except values instead of formulas and no button

    If you look at the original code and take out the three lines starting at ActiveWindow.View = xlPageBreakPreview, then you will see what I am trying to do. The only step left after running that code is getting the result formatted to print.

    Hope that helps a bit.

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Format tab for printing

    Hello ATLGator,

    This macro reproduces the original faithfully without the formulas or button and is renamed according to cell value in "B4".
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Format tab for printing

    Thank you for the new code, but I really need to stick with what I started with and figure out why it's not working. This code will be built upon later. For example, I would also like to add a page footer, and eventually I will have to create a loop.

    Here are the two lines I'm currently using:
    Please Login or Register  to view this content.
    Both are giving me an error. The RightFooter error is "Run-time error '1004': RightFooter method of PageSetup class failed". The PrintArea error is "Run-time error '438': Object doesn't support this property or method". I am not sure how to fix these but everything online that I have found so far looks the same as what I have.
    Last edited by ATLGator; 04-12-2012 at 01:04 PM.

  14. #14
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Format tab for printing

    Hello ATLGator,

    When you assign a value to variable or object, VBA expects to see an equal sign.
    Please Login or Register  to view this content.
    If you have the VBA Help files installed, you should start referencing them. If not then you should download them. It will save you a lot time in the long run.

  15. #15
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Format tab for printing

    Where do I get these files?

  16. #16
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Format tab for printing

    Hello ATLGator,

    If you have the Office 2007 CD, you can load the VBA Help files from there. If Office was pre-installed on your machine then you will need to contact the installer or your IT department if applicable.

    Currently, only the VBA help files for Office 2003 are available for download. There is the Excel 2007 object model reference but it deals only with VBA object, properties and methods pertaining to Excel and not VBA in general. You may find it useful at some point.

    Excel 2007 Object Model Reference

  17. #17
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Format tab for printing

    The equal sign fixed the RightFooter, but not the PrintArea . . . I don't understand why this one is giving me so much trouble.

    Are the help files found by hitting F1 in VBE, or are they something different? If so, I have tried the example given (Worksheets("Sheet1").PageSetup.PrintArea = "$A$1:$C$5") and even though there are no errors, the print area does not change.

+ 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