+ Reply to Thread
Results 1 to 4 of 4

copy Before_print code into new workbook

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Brackley, England
    MS-Off Ver
    Excel 2003
    Posts
    14

    Unhappy copy Before_print code into new workbook

    Afternoon,

    I have a piece of code that copies a worksheet and puts it in a new workbook, then save it under it's own filename. See Below:
    Please Login or Register  to view this content.
    The issue is I want the code that is in the Workbook before_print event to be copied as well. I suppose the the three questions are:

    Is this possible?
    How do you do it?
    If not is there a way to approximate the function of running code before a worksheet is printed?

    I cannot seem to see anything on the internet about this, so I'm not even sure if it's possible. So any help would be much appreciated.

    Thanks in advance

    Rhod

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

    Re: copy Before_print code into new workbook

    Rhod

    1 Yes.

    2 By writing code that writes code, which would require allowing access to the VBA project which may be a security issue.

    3 Not sure what you mean by that.

    Have you considered using a template workbook that has the code for workbook BeforePrint in it?

    If you used a template you could create a new workbook from it and then copy the worksheet into it.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: copy Before_print code into new workbook

    Hello Rhod,

    Why don't you use another approach and instead of adding a new workbook and copying a sheet into it, use Workbook.SaveAs to save the whole of the current workbook and then delete any sheets in the copied workbook that you don't want to be present.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    03-27-2013
    Location
    Brackley, England
    MS-Off Ver
    Excel 2003
    Posts
    14

    Smile Re: copy Before_print code into new workbook

    Both of those idea's sound as if they could work quite well, so i will have a look and see which works best. Thanks very much for both your help. i will let you know!!

+ 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