Word Record macro resolves text formatting on a pasted network

Source: Internet
Author: User

This article will use recorded macros in Word to solve the problem of garbled text formatting on a copy-and-paste network.

This macro code is taken from: Li Wenshu, thank you for his offer.

Technorati Tags: Word macro format correction 1. Create a Word macro

Create a new Word file, click View---> Macro---> Record macro, and the following settings box appears.

After setting up, click Macro---end recording, then click Chahong, check the edit box, pop up the Macro code edit page, copy the macro code at the end of the article to the inside, the final result is as follows:

2. Using macros

When using, create a new blank Word file, then, the text above the page, copy a paragraph of text, and then choose View---> Macro---> Run, you can format the text from the network.

The sample code is just the simplest setting, and the user can customize the special settings to suit their needs.

Sub Formatinternetword ()'Author: Li Wenshu    'Online article copy paste for my use, you will find a lot of documents more than a lot of space, empty line,    'Some use the manual newline character instead of the paragraph mark, so that the first paragraph can not be empty two-pane display.     'these problems affect both aesthetics and the use of paper space (when printing),    'If you delete that labor, it's too big.    'I was in the practical operation of the first use is Stupid kung fu,    'later realized that you can record a macro to replace the collation, save a lot of trouble.     'Replace ^l with ^p. Soft return replaced by hard returnSelection.Find.ClearFormatting'clear the Find box formatSelection.Find.Replacement.ClearFormatting'Clear Replace box formatWith Selection.Find. Text="^l"        . Replacement.text="^p"        . Forward= True'Search Backwards. Wrap =wdfindcontinue. Format= False'do not clear formatting. MatchCase = False'Match Case. MatchWholeWord = False'Match Whole word. MatchByte = False'Full Width. MatchWildcards = False'uncheck "Use wildcards". MatchSoundsLike = False'does not match homonyms. MatchAllWordForms = False'do not look up all forms of a wordEnd with Selection.Find.Execute Replace:=wdReplaceAll'Replace the ^p^p with the ^pSelection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting with Selection.Find. Text="^p^p"        . Replacement.text="^p"        . Forward=True. Wrap=wdfindcontinue. Format=False. MatchCase=False. MatchWholeWord=False. MatchByte=False. MatchWildcards=False. MatchSoundsLike=False. MatchAllWordForms=False End with Selection.Find.Execute Replace:=wdReplaceAll'Replace a space with the correct formatSelection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting with Selection.Find. Text=" "        . Replacement.text=" "        . Forward=True. Wrap=wdfindcontinue. Format=False. MatchCase=False. MatchWholeWord=False. MatchByte=False. MatchWildcards=False. MatchSoundsLike=False. MatchAllWordForms=False End with Selection.Find.Execute Replace:=wdReplaceAll'Set Page LayoutWith Activedocument.pagesetup. Orientation= wdOrientLandscape'page orientation is landscape. TopMargin = CentimetersToPoints (1.27)'Top Margin. BottomMargin = CentimetersToPoints (1.27)'Bottom Margin. LeftMargin = CentimetersToPoints (1.27)'left margin. RightMargin = CentimetersToPoints (1.27)'Right Margin. Gutter = centimeterstopoints (0)'Binding Line 0cm. HeaderDistance = CentimetersToPoints (1.5)'Header. FooterDistance = CentimetersToPoints (1.75)'Footer. PageWidth = CentimetersToPoints ( -)'Paper Width. PageHeight = CentimetersToPoints (35.4)'High Paper. SectionStart = Wdsectionnewpage'Section Start Location: New Page. OddAndEvenPagesHeaderFooter = False'do not tick "odd and even page different". DifferentFirstPageHeaderFooter = False'uncheck the "home page is different". VerticalAlignment = Wdalignverticaltop'The vertical alignment of the page is top- aligned. SuppressEndnotes = False'do not hide endnotes. MirrorMargins = False'do not set the internal and external margins of the home page. bookfoldrevprinting = False'do not set manual duplex printing. Bookfoldprintingsheets =1 'default number of printed copies is 1. Gutterpos = Wdgutterposleft'Gutter on left. LayoutMode = Wdlayoutmodelinegrid'layout mode is "Specify row grid only"End with'Set paragraphWith activedocument.paragraphs. Characterunitfirstlineindent=2        . Alignment= wdAlignParagraphLeft'Align Left. SpaceBefore =0 'Spacing before paragraph. SpaceAfter =0 'spacing after paragraph. LineSpacingRule = wdlinespace1pt'single line spacing, you can customize the value. WidowControl =-1 'Orphan control, you can control the TAB key not to be too long. KeepWithNext =0 'same page as next paragraph. KeepTogether =0 'no pagination in paragraph. PageBreakBefore =0 'pre-paragraph paginationEnd with'Delete all hyperlink bookmarks and linksWith ActiveDocument Dim MyLink As Hyperlink Dim mybookmark As Bookmark Dim MyField as Field for each myLink in. Hyperlinks'Mylink.delete'Remove all Hyperlinks Next myLink for every mybookmark in. Bookmarks Mybookmark.delete"'Delete"links"In the"Bookmark"(gray brackets Mark) Next MyBookmark for each myField in. fields'Myfield.unlink'Remove all annoying links Next MyField End with Activedocument.save end Sub

Word Record macro resolves text formatting on a pasted network

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.