How to: send documents to a printer

Source: Internet
Author: User
Tags strfind

From: http://www.cnblogs.com/hone/archive/2005/12/29/307302.html

AvailablePrintoutTo send a Microsoft Office Word document (or part of the document) to a printer. FromApplicationOrDocumentObject callPrintout ().

Print Document

    • The followingCodePrint the activity document with all default options:

      Thisdocument. printout ()

PrintoutThe method has multiple optional parameters, allowing you to fine-tune the way the document is printed. The following table summarizes these parameters.

Parameters Description
Background If this parameter is set to true, you can continue to process documents printed by word.
Append AndOutputfilenameParameters are used together. If this parameter is set to true, You can append the specified document nameOutputfilenameAfter the file name specified by the parameter. Set to false to overwriteOutputfilename.
Range Page range. For anyWdprintoutrangeEnumeration:Wdprintalldocument,Wdprintcurrentpage,Wdprintfromto,WdprintrangeofpagesOrWdprintselection.
Outputfilename IfPrinttofileTrue. This parameter specifies the path and file name of the output file.
From RangeSetWdprintfromtoStart page number.
To RangeSetWdprintfromtoThe ending page number.
Item The entry to be printed. Can be anyWdprintoutitemEnumeration:Wdprintautotextentries,Wdprintcomments,Wdprintdocumentcontent,Wdprintkeyassignments,Wdprintproperties,Wdprintstyles.
Copies The number of copies to print.
Pages The page number to be printed and the page number range are separated by commas. For example, "2, 6-10" indicates printing 2nd pages and 6th, 7, 8, 9, and 10 pages.
Pagetype The type of the page to be printed. Can be anyWdprintoutpagesConstant:Wdprintallpages,Wdprintevenpagesonly,Wdprintoddpagesonly.
Printtofile Set true to send printer commands to documents. Make sure to useOutputfilenameSpecify a file name.
Collate This parameter is used to print multiple copies of a document. If it is set to true, all pages of this document will be printed before the next copy is printed.
Filename Applicable onlyApplicationObject. The path and file name of the document to be printed. If this parameter is not used, word prints the active document.
Manualduplexprint Set to true to print dual-sided documents without dual-sided printers.

Common printout parameters.

Print the first page of the activity document

  • The following process prints the first page of the activity document:

    'Visual basic friend sub printoutdoc () thisdocument. printout (_ Background: = true, _ append: = false, _ range: = word. wdprintoutrange. wdprintcurrentpage, _ item: = word. wdprintoutitem. wdprintdocumentcontent, _ copies: = "1", _ pages: = "1", _ pagetype: = word. wdprintoutpages. wdprintallpages, _ printtofile: = false, _ collate: = true, _ manualduplexprint: = false) end sub // C # Internal void printoutdoc () {object Mytrue = true; object myfalse = false; object missingvalue = type. missing; object range = word. wdprintoutrange. wdprintcurrentpage; object items = word. wdprintoutitem. wdprintdocumentcontent; object copies = "1"; object pages = "1"; object pagetype = word. wdprintoutpages. wdprintallpages; thisdocument. printout (ref Mytrue, ref myfalse, ref range, ref missingvalue, ref items, ref copies, ref pages, ref pagetype, ref myfalse, ref Mytrue, ref missingvalue, ref myfalse, ref missingvalue, ref missingvalue );}
    How to: Search for text in a Word document

    FindObjectSelectionAndRangeYou can use any of the two to search for text. The "replace" command is an extension of the "Search" command.

    UseSelectionWhen the object searches for text, all the specified search conditions only apply to the selected text. IfSelectionIs the insertion point, the entire document is searched. If you find an item that matches the search criteria, select the item that will be automatically changed to highlight the found item.

    Use selection object to find text

    • The following process searches for the string "Find me ". After finding the first one, it highlights the word and displays a message box.
      'Visual basic friend sub selectionfind () dim strfind as string = "Find me" with thisapplication. selection. find. clearformatting (). TEXT = strfind if. execute = true then MessageBox. show ("text found. ") else MessageBox. show ("the text cocould not be located. ") end if end with end sub // C # Internal void selectionfind () {string strfind =" Find me "; word. find FND = thisapplication. selection. find; fnd. clearformatting (); fnd. TEXT = strfind; object missingvalue = type. missing; If (FND. execute (ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue) {MessageBox. show ("text found. ");} else {MessageBox. show ("the text cocould not be located. ");}}

    Note that,FindThe condition is cumulative, which means that a condition will accumulate with the previous search condition. You can use. Clearformatting ()Method to clear the format settings for the last search.

    UseRangeObject Search Text allows you to search for text without displaying any content on the user interface. If you find the text that matches the search criteria,FindMethod returns true; otherwise, false. If the text is found, the method will be redefined.RangeObject To match the search criteria.

    Use the range object to search for text

    1. DefineRangeObject.

      'Visual basic dim RNG as word. range = thisdocument. Paragraphs (2). Range // C # Word. Range RNG = thisdocument. Paragraphs [2]. range;
    2. UseFindMethod, first clear any existing format setting options, and then search for the string "Find me ".
      'Visual basic with RNG. find. clearformatting () If. execute (findtext: = "Find me") Then // C # word. find FND = RNG. find; fnd. clearformatting (); object missingvalue = type. missing; object findstr = "Find me"; if (FND. execute (
    3. Display the search result in the message box, and finally selectRangeTo make it visible.
      'Visual basic MessageBox. show ("text found. ") else MessageBox. show ("text not found. ") end if end with RNG. select () // C # {MessageBox. show ("text found. ");} else {MessageBox. show ("text not found. ");} RNG. select ();

      If the search fails, the second segment is selected. if the search is successful, the search criteria are displayed.

    The complete method is as follows:

     'visual basic friend sub rangefind () dim RNG as word. range = _ thisdocument. paragraphs (2 ). range with RNG. find. clearformatting () If. execute (findtext: = "Find me") Then MessageBox. show ("text found. ") else MessageBox. show ("text not found. ") end if end with RNG. select () end sub // C # Internal void rangefind () {word. range RNG = thisdocument. paragraphs [2]. range; word. find FND = RNG. find; fnd. clearformatting (); object missingvalue = type. missing; object findstr = "Find me"; if (FND. execute (ref findstr, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue, ref missingvalue) {MessageBox. show ("text found. ");} else {MessageBox. show ("text not found. ");} RNG. select () ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.