Word Macro instance

Source: Internet
Author: User
Tags password protection

The basic functions of this macro are as follows: convert each line in a file.

Before conversion: 1 1001 AAA 0

After conversion: 1,1001, "AAA", "AAA", 0

Sub convert ()
Selection. Find. clearformatting
Selection. Find. Replacement. clearformatting
With selection. Find
. Text = "^ t"
. Replacement. Text = ","
. Forward = true
. Wrap = wdfindcontinue
. Format = false
. Matchcase = false
. Matchwholeword = false
. Matchbyte = true
. Matchwildcards = false
. Matchsoundslike = false
. Matchallwordforms = false
End
Selection. Find. Execute Replace: = wdreplaceall
Selection. homekey unit: = wdstory
For I = 1 to activedocument. Paragraphs. Count
Selection. homekey unit: = wdline
Selection. Find. clearformatting
Selection. Find. Replacement. clearformatting
With selection. Find
. Text = ","
. Replacement. Text = ""
. Forward = true
. Wrap = wdfindcontinue
End
Selection. Find. Execute
Selection. Find. Execute
With selection. Find
. Text = ","
. Replacement. Text = ","""
. Forward = true
. Wrap = wdfindcontinue
End
With Selection
If. Find. Forward = true then
. Collapse direction: = wdcollapsestart
Else
. Collapse direction: = wdcollapseend
End if
. Find. Execute Replace: = wdreplaceone
If. Find. Forward = true then
. Collapse direction: = wdcollapseend
Else
. Collapse direction: = wdcollapsestart
End if
. Find. Execute
End
With selection. Find
. Text = ","
. Replacement. Text = ""","""
. Forward = true
. Wrap = wdfindcontinue
End
With Selection
If. Find. Forward = true then
. Collapse direction: = wdcollapsestart
Else
. Collapse direction: = wdcollapseend
End if
. Find. Execute Replace: = wdreplaceone
If. Find. Forward = true then
. Collapse direction: = wdcollapseend
Else
. Collapse direction: = wdcollapsestart
End if
. Find. Execute
End
With selection. Find
. Text = ","
. Replacement. Text = ""","
. Forward = true
. Wrap = wdfindcontinue
End
With Selection
If. Find. Forward = true then
. Collapse direction: = wdcollapsestart
Else
. Collapse direction: = wdcollapseend
End if
. Find. Execute Replace: = wdreplaceone
If. Find. Forward = true then
. Collapse direction: = wdcollapseend
Else
. Collapse direction: = wdcollapsestart
End if
. Find. Execute
End
Next I
End sub

Refer to the following document for reprinting:

Application Object

--------------------
(301) application. activeprinter 'get the current printer
(302) application. height' current application Program Document height
(303) application. width' the width of the current application document
(304) application. Build 'get the word version number and the compilation sequence number
(305) application. Caption 'current Application name
(306) application. defaultsaveformat 'returns an empty string, indicating a Word document
(307) application. displayrecentfiles ': returns whether the status of the most recently used document is displayed.
(308) application. Documents. Count 'returns the number of currently opened documents
(309) application. fontnames. Count 'returns the number of available fonts.
(310) application. Left 'returns the horizontal position of the current document.
(311) application. macrocontainer. fullname 'returns the current document name, including the path
(312) application. normaltemplate. fullname 'returns the name and location of the standard template in the document.
(313) application. recentfiles. Count 'returns the number of recently opened documents
(314) application. system. countryregion 'returns the region where the application is located. Code
(315) application. system. freediskspace 'returns the available disk space of the application.
(316) application. system. horizontalresolution 'returns the horizontal resolution of the display.
(317) application. system. verticalresolution 'returns the vertical resolution of the display.
(318) application. system. languagedesignation 'returns the language used by the system.
(319) application. system. mathcoprocessorinstalled 'returned whether the system has a mathematical coprocessor installed
(320) application. system. operatingsystem 'returns the current operating system name
(321) application. system. processortype 'returns the computer processor name
(322) application. system. version 'returns the version number of the operating system.
(323) application. Templates. Count 'returns the number of templates used by the application.
(324) application. Username 'returns the Application User Name
(325) application. version' returns the application version number.
----------------------
Documents/Document Object
----------------------
(326) activedocument. attachedtemplate. fullname ': returns the Template Name and template location used in the current document.
(327) activedocument. bookmarks. Count 'returns the number of bookmarks in the current document.
(328) activedocument. characters. Count 'returns the number of characters in the current document.
(329) activedocument. codename 'returns the code name of the current document
(330) activedocument. Comments. Count 'returns the number of comments in the current document.
(331) activedocument. endnotes. Count 'returns the number of end notes in the current document.
(332) activedocument. Fields. Count 'returns the number of fields in the current document.
(333) activedocument. Footnotes. Count 'returns the number of footers in the current document.
(334) activedocument. fullname 'returns the full name and location of the current document.
(335) activedocument. haspassword' whether the current document has password protection
(336) activedocument. hyperlinks. Count 'returns the number of links in the current document.
(337) activedocument. Indexes. Count 'returns the number of indexes in the current document.
(338) activedocument. listparagraphs. Count 'returns the number of projects or project symbols in the current document.
(339) activedocument. listtemplates. Count 'returns the number of list templates used in the current document
(340) activedocument. Paragraphs. Count 'returns the number of paragraphs in the current document.
(341) activedocument. Password = XXX' set the password used to open the file
(342) activedocument. readonly 'to check whether the current document is read-only.
(343) activedocument. saved' whether the current document is saved
(344) activedocument. Sections. Count 'number of sections in the current document
(345) activedocument. Sentences. Count 'number of statements in the current document
(346) activedocument. shapes. Count 'number of shapes in the current document
(347) activedocument. Styles. Count 'number of styles in the current document
(348) activedocument. Tables. Count 'number of tables in the current document
(349) activedocument. tablesofauthorities. Count 'returns the number of citation directories in the current document.
(350) activedocument. tablesofauthoritiescategories. Count 'returns the number of cited directory categories in the current document.
(351) activedocument. tablesofcontents. Count 'returns the number of directories in the current document.
(352) activedocument. tablesoffigures. Count 'returns the number of chart directories in the current document.
----------------------
Paragraphs/Paragraph object
----------------------
(353) selection. Paragraphs. Count 'returns the number of paragraphs in the selected area.
(354) selection. Paragraphs. First 'returns the first segment of the selected region
(355) activedocument. Paragraphs (1). leftindent 'returns the left indent value of the first section of the current document.
(356) activedocument. Paragraphs (1). linespacing 'returns the line spacing of the first segment in the current document.
(357) activedocument. Paragraphs (1). outlinelevel 'returns or sets the outline level of the first section in the current document.
(358) activedocument. Paragraphs (1). rightindent 'return the right indent of the first section of the current document
(359) activedocument. Paragraphs (1). spacebefore 'returns the Spacing Before the first section of the current document.
(360) activedocument. Paragraphs (1). spaceafter 'return the spacing after the first segment of the current document
(361) activedocument. Paragraphs (1). range. Text 'returns the first section of the current document.
(362) activedocument. Paragraphs (1). range. style. namelocal 'return the style name of the first application in the current document.
(363) activedocument. Paragraphs (1). range. style. descr apply ption 'return the detailed description of the applied style in the first section of the current document.
(364) activedocument. Paragraphs (1). range. style. Font. name' returns the name of the first applied style in the current document.
(365) activedocument. Paragraphs (1). range. style. Font. namefareast 'returns or sets an East Asian Font Name.
(366) activedocument. Paragraphs (1). range. style. Font. Size 'returns or sets the font size of the style applied in the first section of the current document.
(367) activedocument. Paragraphs (1). range. style. Font. Spacing 'return or set the Character Spacing
(368) selection. Words. count the number of words in the selected area
-------------
Sentences object
-------------
(369) selection. Sentences. Item (1) 'content of the first sentence in the selected region
----------
Words object
----------
(371) activedocument. Words (1). select' select the first word in the current document
(372) activedocument. range. Words (1). insertafter "I love you! "'Insert" I love you "after the first word in the current document"
-------------
Characters object
-------------
(373) selection. characters. Count 'the number of characters in the selected area of the current document
(374) activedocument. Paragraphs (1). range. insertparagraphafter Insert a new section after the first section of the current document
------------------
Sections/section object
------------------
(375) activedocument. Sections. First Section of the current document
(376) activedocument. Sections. First. pagesetup. bottommargin 'bottom margin of the page on which the first section of the current document is located
(377) activedocument. Sections. First. pagesetup. leftmargin 'left margin of the page on which the first section of the current document is located
(378) activedocument. Sections. First. pagesetup. rightmargin 'right margin of the page on which the first section of the current document is located
(379) activedocument. Sections. First. pagesetup. topmargin 'top margin of the page on which the first section of the current document is located
(380) activedocument. Sections. First. pagesetup. papersize 'returns or sets the page size of the first section of the current document.
(381) activedocument. Sections. First. pagesetup. pageheight 'returns or sets the height of the page on which the first section of the current document is located.
(382) activedocument. Sections. First. pagesetup. pagewidth 'return or set the width of the page on which the first section of the current document is located.
(383) activedocument. Sections. Add range: = myrange Add a new section in the current document
(384) activedocument. Sections. Item (2) 'section 2 of the current document
(385) activedocument. Sections. Last. range. insertafter "document ended! "'Add the text" End of the document "to the end of the last section of the current document !"
----------
Range object
----------
(386) activedocument. Range (START: = 0, end: = 10) 'indicates a range object consisting of the first 10 characters of the current document.
(387) set myrange = activedocument. Range (_
Start: = activedocument. Paragraphs (2). range. Start ,_
End: = activedocument. Paragraphs (4). range. End) 'sets the section 2nd to section 4th of the current document as a range object.
(388) activedocument. Paragraphs (1). range. copy' copy the first section of the current document
(389) selection. Copy
Documents. Add. content. paste copy the selected content to the new document.
(390) activedocument. bookmarks ("book1"). Copy name: = "book2" 'Copy book2 bookmarks to the position marked by book1 bookmarks
(391) selection. goto what: = wdgotoline, which: = wdgotoabsolute, Count: = 4' move the selected content to 4th rows in the document
(392) selection. goto what: = wdgototable, which: = wdgotonext move the selected content to the 1st cells in the next table
(393) selection. range. AutoFormat 'format the selected content
(394) activedocument. content. Font. Name = "Arial" ': Set the font of the current document to italic.
(395) activedocument. content. Select
Selection. delete' Delete the content in the current document
-----
Others
-----
(396) documents. add' Add a new document
(397) set mytable = activedocument. Tables. Add (selection. Range, 2, 2) 'Add a table with two rows and two columns in the selected area of the current document
(398) Open "C:" my.txt "for input as #1 'open a file for input and set it to 1
(399) line Input #1, textline' read files opened for input and numbered 1
(400) close # 1' close the file numbered 1

 

 

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.