VBA & Word: Which Sections will be printed?

I have implemented the event DocumentBeforePrint with Word 2013.
I've modified the backstage print view where the user can select a text (stamp) which will be inserted as a watermark and removed after the print has been done.
In the event DocumentBeforePrint I would like to get the information what the user wants to print (All of the document, or only certain sections of it.) Because setting the watermark in the Footer of each Section takes up some time and I would like to narrow
it down and insert the watermark only in the Section which will be printed.
Thanks for any help! Martin

In that case, you'd probably need to use a DocumentBeforePrint macro, coded along the lines of:
Private Sub wdApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
Dim StrPrn As String, StrRng As String
'Retrieve the print parameters from the FilePrint Dialog
With Application.Dialogs(wdDialogFilePrint)
    'If Print =
    'All, StrPrn = 0
    'Current Page, StrPrn = 2
    'Pages, StrPrn = 4
    StrPrn = .Range
    'If StrPrn = 4, then StrRng holds the range to be printed
    StrRng = .Pages
End With
Select Case StrPrn
  Case 0: StrRng = "1" & "-" & ActiveDocument.Sections.Count
  Case 2: StrRng = Selection.Sections.First.Index
  Case 4
    If InStr(StrRng, "p") > 0 Then
      MsgBox "Please specify only Section #s", vbExclamation
      Cancel = True
      Exit Sub
    End If
    StrRng = Replace(StrRng, "s", "")
End Select
StrRng = ParseNumberString(StrRng, ",", "-")
'StrRng now holds an itemised list of Section #s for further processing
MsgBox StrRng
End Sub
Function ParseNumberString(StrIn As String, strSS, strGS)
Dim i As Long, j As Long, StrTmp As String, Arr As Variant
Arr = Filter(Split(StrIn, strSS), strGS)
For i = 0 To UBound(Arr)
  StrTmp = ""
  For j = Val(Arr(i)) To Split(Arr(i), strGS)(1)
    StrTmp = StrTmp & strSS & j
  Next
  StrIn = Replace(StrIn, Arr(i), Mid(StrTmp, 2))
Next
ParseNumberString = StrIn
End Function
To use code like this, see:
http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm
and:
http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm
Note that I haven't included the code that actually adds the watermarks - all it now outputs is a message box showing the sections to be processed. I'll leave that part to you. I also haven't tested whether you can actually reliably retrieve the required
data this way - you can indeed retrieve it from the Print Dialogue, but doing that directly ordinarily doesn't return the values you're interested in until after the print job has been submitted.
Cheers
Paul Edstein
[MS MVP - Word]

Similar Messages

  • C4650 Will only print black from the internet. MS Word and PS will not print in black but has color.

    Before you think I just haven't tried anything, let me run you down with the whole lot:
    -HP PhotoSmart C4650
    -Windows Vista
    -Problem: My printer won't print in black --but-- this only goes for Microsoft applications it seems. If I have a page of text in black, when printing from MS Word, the page comes out blank, however the printer is actually "printing" back and forth. IF, however I print from my browser, from email, or a webpage, picture, google docs, etc, black prints *just fine.* So far this holds true for both MS Word and PhotoShop CS5. Issue: Black ink simply doesn't print from any program other than a browser.
    -NO. The cartridge isn't empty. NO. It's not incompatible. NO. The cartridge head isn't dry and I am not going to soak it in water. This is a new cartridge. It's the official HP brand.
    I've done a search and I've found that a few people seem to have this "only print from the internet" problem, however none of these was solved. The only advice that an HP support member gave to one of them is to "install XP service pack 2" however.. I am not running XP. A few other people get the opposite issue where they can only print color from the internet and not from the computer's applications.
    I don't know much about printers but it sounds like some kind of driver issue. Yes. I've already searched for, uninstalled and reinstalled drivers. Whenever I have to print something, I now try to open it up in my firefox just so I can be able to print black. It's quite the hassle. Almost seems like some kind of ploy to cause people to buy new ink cartridges when it's not really empty.
    -Yes, I have also uninstalled and reinstalled the printer.
    -Updated my windows (although idk how that would help. But I know it's going to be a suggestion anyway.)
    Is there any known fix or should i chuck it off the balcony and go get a lexmark?

    Hi lisaloyd,
    Welcome to the HP Forums, I hope you enjoy your experience! To help you get the most out of the HP Forums I would like to direct your attention to the HP Forums Guide First Time Here? Learn How to Post and More.
    I see that you are having issues printing in colour.  I also see that you are using a Lexmark printer. I would advise you to get into contact with Lexmark so that they can show you how to navigate through the printing software that they provide.
    Please click on the following link to get to Lexmark Support.
    Thank you for your time.
    Click the “Kudos Thumbs Up" at the bottom of this post to say “Thanks” for helping!
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    W a t e r b o y 71
    I work on behalf of HP

  • Have a G400, OS10.4.11. Need 10.5 or later to install a new printer. Which one will run best? How do I upgrade?

    Have a G400, OS10.4.11. Need 10.5 or later to install a new printer.
    1) Which one will run best?
    2) How do I upgrade?

    It's probably cheaper to buy a new printer & sell the existing on on ebay.
    I have the Cannon pixma mg3120  works fine for me with mac os x 10.4.11.  I am able to refill the color ink jet cartridge.  Press reset + color copy button for 10 seconds.
    http://www.amazon.com/Canon-MG3120-Wireless-All-In-One-5289B019/dp/B005TI2Q8M
    Mac OS® X v10.4.11 to v10.6.x
    http://www.usa.canon.com/cusa/consumer/products/printers_multifunction/photo_all _in_one_inkjet_printers/pixma_mg3120
    What is a G400?
    You may want to post machine info.
    blue apple > about this mac > more info button. Click on the hardware line. It has a little triangle in front of the word hardware.
    Leave out the serial number.
    Example:
    Machine Name: iMac
    Machine Model: PowerMac4,1
    CPU Type: PowerPC 750 (33.11)
    Number Of CPUs: 1
    CPU Speed: 600 MHz
    L2 Cache (per CPU): 256 KB
    Memory: 768 MB
    Bus Speed: 100 MHz
    Boot ROM Version: 4.1.9f1

  • Printer will not print word documents or documents from internet however does a test print

    My printer will not print word documents or documents from the internet.  However it does complete a test print.  I have uninstalled and reinstalled printer.  I have disabled and enbled the firewall and have run the test doctor programme, which has been unable to identify any problems.  I have a HP deskjet 3050A all in one J611 series printer.

    Sorry that you are having a problem with printing word documents and internet. 
    Are you connected USB or wireless?
    You can try to download an alternative driver and check to see if that works. (Shane_R) has a great post on how to do so. 
    The deskjet 990c is usually the better one. 
    http://h30434.www3.hp.com/t5/Printer-All-in-One-So​ftware-Drivers-e-g-Windows-8/How-to-Assign-Alterna​...
    **Click the KUDOS star on the left to say 'Thanks'**
    Please mark a reply "ACCEPTED AS SOLUTION" if it solved your problem, so others can find it.

  • Hi there can anyone help as i am unable to contact Apple for support with my printer which will not print after recent software update? this is the email i tried to send to apple with no success, can anyone help please.......Dear Apple, I'm pulling my hai

    Hi there,
    Can anyone out there help, after a recent Apple software update my Epson Stylus Photo RX640 will no longer print, every other aspect of the printer works fine including the scanner but it just will not print, I sent an email to apple but all i got was an automated reply directing me to their support page, the email i sent is below this explains in full what the problem is & what i have done to try & fix this problem.
    Dear Apple,
    I'm pulling my hair out after a recent software update from apple, since this update my Epson Stylus Photo RX640 will not print, every other function of the printer including the scanner works fine,
    Please see attached file of the error message coming up in the print queue.
    I have spent days trying to fix this, i have been onto Epsons website & followed their resolution for this error message to no avail, after contacting them again with the results i got an email back saying : In response to your email, the RX640 will use an inbox or gutenprint driver on Mac OS X 10.6.8, it is not compatible with an Epson driver.
    I have also tried re-installing drivers from original Discs for the printer but it still will not print, obviously this error has been caused by Apple's latest software update, when are Apple going to fix this problem? i need my printer working ASAP.
    Regards
    Brian
    PS i obviously can't attach the error message so here it is:    Error:/Library/Printer/Epson/inkjetprinter 2/filter/rastertoescpll.app/contents/mac os/rastertoescpll/failed
    Thank You all in advance
    Regards
    Brian

    It is hardly Apple's fault that Epson can't/won't update their driver, but at least Epson suggest that you use the Gutenprint driver, which in any case is far better that what Epson offer.
    You can get it here:
    http://gimp-print.sourceforge.net/
    You can download the latest version from here:
    http://sourceforge.net/projects/gimp-print/
    Have you downloaded the recent Apple update to Epson drivers?
    http://support.apple.com/kb/DL1398

  • We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader. For which, We created and execute the below command line to call Adobe Reader and print the PDF on a

    We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader. For which, We created and execute the below command line to call Adobe Reader and print the PDF on a printer."C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /T "\\<Application Server>\Report\<TEST.PDF>" "<Printer Name>". Current Situation: The above command line parameter when executed is working as expected in a User's Workspace. When executed in a command line on the Application Server is working as expected. But, the same is not working while executing it from Deployed environment.Software being used: 1. Adobe 11.0 enterprise version. 2. Webshpere Application Server 8.5.5.2. Please let us know if there is a way to enable trace logs in Adobe Reader to further diagnose this issue.

    This is the Acrobat.com forum.  Your question will have a much better chance being addressed in the Acrobat SDK forum.

  • HP 2480 all in one printer will not print documents, i.e., Word, e-mail, etc.

    I have installed the Printer diagnostic utility and the test page printed, so I thought my problem was solved.  However, the printer still will not print anything!  I have tried pictures, Word documents, e-mail documents, etc.  The printer was working fine a week ago, and I have restored the computer to an earlier time, but nothing has fixed the problem!

    I have the same problem with HP Photosmart C4750!!
    Anybody have solution?

  • Bought new hp8600 plus printer. tried to print a page from word. will not print wireless.

    Bought this HP8600Plus printer because it indicated wireless.
    Installed disk and tried to print Word doc. It will not print.

    Download and run this utility: http://h10025.www1.hp.com/ewfrf/wc/softwareDownloadIndex?softwareitem=mp-104282-2&cc=us&dlc=en&lc=en...
    What does it say?
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • TS1647 My Macbook Pro will not print anything from any program. I've reinstalled the drivers. I get an error message in Word that says, "Word could not communicate with printer." Any ideas?

    My Macbook Pro will not print anything from any program. I've reinstalled the drivers. I get an error message in Word that says, "Word could not communicate with printer." Any ideas?

    Be sure to try restarting, if you have not done so since this problem occurred.  You should also power off the printer while you do the restart...
    If that does not help, you can try resetting the printing system.  Open System Preferences Print & Scan (or Print & Fax) pane.  In the sidebar with list of printers, right (control) click anywhere.  Select Reset printing system.  You will have to add back your printers after you do this.

  • Will not print word documents mac

    recently installed a hp officejet 8600 plus on a mac with 10.6.8. initially everything was working properly...printing from email and word, scanning and faxing. couple days later, i am not able to print from mac word and occacionally having ssues printing certain mails. i have followed the hp steps to resolve commun printing issues ...delete printer and add printer on devices and power reset printer itself. no luck.

    Hello cantprint:
    Thank you for your inquiry.
    I understand that after you initial installation you  were able to print , but you are now having difficulties printing from mail and word.
    I need some more information please.
    Has there been any updates or changes?
    Can you print from text edit?
    How is the printer connected?
    What mail program are you printing from?
    When you said mac word did you mean ms word for mac or pages?
    Please reply back and I will be happy to assist you further.
    Sparkles1
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the bottom right to say “Thanks” for helping!

  • HT3412 Want to order books but received the following message, "your book appears to have unedited text which will not print in your book."  What does that mean?

    Please help.  Want to order completed book but received the following message, "your book appears to have unedited text which will not be printed in your book."  What does that mean?  Why did the program let me use text that will not print?

    Go thru every page in the book and look for any text box.  Unused text boxes will have somegthing like this in them:
    or this:
    Just put a space in those text boxes where you didn't put text previously.  Check the inside flaps of the book jacket also.

  • Cannot print in Adobe 9 it will only print to file which does not work

    I cannot print a PDF file that is in Adobe 9.  It is not the file, I opened several other files and they all do the same thing.  INstead of printing.  When I click OK after choosing the printer, it goes into a print to file mode.  The print to file always fails and then it will nto print.  This morning it was working fine.  Now it will not print. It may have installed an update to Adobe 9, I do not remember it being 9 before.   I am in trouble if I cannot print tonight.  Any ideas?

    WHat is a "print dialogue?n  How can I find it"  There is nothing that I can find called print dialogue.
    Where do nI find "print to file in order to disable it?

  • VBA Word Find and Replace characters but excluding certain characters

    I am trying to write VBA code in Word that I will eventually run from a VBA Excel module. The aim of the project is to find specific strings in the open Word document that have length of either one or two characters and are of a certain format, and replace
    them with other strings in the same format. This is to do with transposing (i.e. changing the musical key) of chord symbols in a songsheet in Word. The Find and Replace strings are contained in ranges in an Excel workbook, which is why I want to eventually
    run the code from Excel. I'm much more experienced in writing VBA code in Excel than in Word, and I'm fairly confident with transferring the 'Word VBA' code into an Excel module.
    At the moment I'm trying out code entirely in Word, and I've come across a stumbling block. For example, I want it to Find "A" and replace with "B",
    BUT only if the "A" is NOT followed by "#" (sharp) or "b" (flat).
    Here is the code I've got in Word VBA, which I obtained by editing code produced by the recorder:
    Sub F_R()
    'Find text must have specific font
    With Selection.Find.Font
    .Bold = True
    .Underline = wdUnderlineWords
    .Superscript = False
    .Subscript = False
    End With
    'Replacement text must have specific font
    With Selection.Find.Replacement.Font
    .Bold = True
    .Underline = wdUnderlineWords
    .Superscript = False
    .Subscript = False
    End With
    'Find & Replace strings
    With Selection.Find
    .Text = "A" 'hard-coded here for testing, but this will
    'eventually be referenced to a cell in Excel
    .Replacement.Text = "B" 'hard-coded here for testing, but this will
    'eventually be referenced to a cell in Excel
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = True
    .MatchWholeWord = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    For the Find & Replace section I want to do something like:
    With Selection.Find
    .Text = "A"
    .Text <> "A#"
    .Text <> "Ab"
    .Replacement.Text = "B"
    End With
    - but this produces a syntax error, presumably because you can have only one .Text line (or it won't accept <>?)
    I tried adopting the way of excluding chars when using the Like operator, and while it compiles, it will not replace
    any "A":
    With Selection.Find
    .Text = "A[!b#]"
    .Replacement.Text = "B"
    End With
    I suspect that I'm going to have to change tack completely in the way I'm doing this. Do you have any suggestions, please?
    The chord names/symbols are preceded/succeeded by either spaces or paragraph returns and can look like these, for example (all Font Bold and Underlined words only):
    C<sup>7</sup>
    Dm<sup>7</sup>
    Eb<sup>-5</sup>
    Bb<sup>+11</sup>
    F#m<sup>7</sup>
    i.e. [ABCDEFG][b # | optional][m |optional][- + | superscript, optional][2 3
    5 6 7 9 11 13 | superscript, optional]
    The crux of my problem is that the note A should be treated as entirely distinct from Ab or A# (and similar for other flattened/sharpened notes).
    Sorry for long post.

    Hi Ian,
    It is not easy to find Microsoft forums. However this forum is for the Visual Studio Net version. 
    Try this forum for VBA.
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=isvvba
    Success
    Cor

  • File will not print, just hangs acrobat

    Hi all.
    As usual a deadline is looming and my lovely document created in indesign is now exported to pdf and ready to print.
    However when I try to print all that happens it it endlessly sits their spinning, with no print.
    Because acrobat does not 'crash' I cannot asertain what has caused it too happen.
    Any ideas what I can do, its really important I get this 100 page document printed 5 times very soon!

    was the file originally created from MS Word?
    And does the Word document have section Breaks?
    If so Adobe/MS have a long standing bug that has been around since Acrobat 1 and  Office 4.2. Acrobat can't figure out MS Word's Section Breaks.
    Up until Word 2008 they had a Problem with Page Breaks when Miicrsoft came up with there own word to PDF Converter. Both blame apple which is downright silly because Up until version Acrobat 5.5 and word XL they worked on OS9 and lower which written in either Objective-C or C++ And the printing system had nothing to do with PDF. So that arguement is down right silly. Micrsoft is  so paranoid about its code beeing stolen they refuse to allow companies such Adobe see the code. If they could I feel the problems would be fixed with 6 months. But sadly we are talking about a 15 year old problem, no one refuses to fix.
    what it does instead of jumping to a new section, or new Page, it create a new pdf file.  You can tell if this is the problem by open printer item in the Dock whil it printing. If this is the case you will see a series of PDF's in the Print Cue.
    Another problem could be that your Printer doesn't have enough memory it it is a Postscript printer many can have memory added to them.

  • LaserJet 5000 will not print more than one copy at a time.

    We have recently moved our office.  A LaserJet 5000 which is used as an office printer is shared through one of the computers on the network in the exact same way it was more we moved.  But since the move it will not print multiple copies of the same document no matter how many copies the software tells the printer to print it will only print one copy then it stops.  Before the moved it worked fine.  If the software program such as Word told it to print 100 copies it printed 100 copies now one is the limit.   So if you want to printmore than one you have to hit print that many times.  It has 172 MB RAM.  Does anyone have any ideas of what might have happened????

    I have the same issue with a photosmart 2410xi. Did you ever get yours figured out?

Maybe you are looking for

  • Reset upto mobile me does not work

    I have an iphone macbook and pc I want to syuc all contacts etc. All went fine and I uploaded from my pc a contacts list, but now a week later the details on the mobileme is differant to the pc ie lost addresses and mobileme is trying to download thi

  • Multiple images from a database

    Hi I was wondering if you could help me. I use Dreamweaver CS3. I have created a database with 3 fieldnames: ID | Name | Picture. I have managed to display all the pictures (rsMypictures) on my PHP page (I use PHP + MYSQL). I have 3 columns on each p

  • After upgrading to NW 7.01, issue with height/width using %

    We upgraded our backend xRPM ABAP Stack to Netweaver 7.01 from 7.0. Now, our Adobe forms (ADS sits on a java Netweaver 7.0 server) are not displaying correctly - we launch them from ABAP Web Dynpro into a separate window. The forms appear in a small

  • I accidently deleted user account how can I get to my files?

    I decided to remove my earlier user account and discovered medical records, college exams, notes, girl friends I have dated, et,et,et, were deleted too! Can anyone help me get the files back? PLEASE HELP!!!!!!!!!!!!!!!

  • Edit pdf with Adobe Reader Pro XI?

    How do I edit a PDF file with Adobe Reader Pro XI?