日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

word 宏 实例

發(fā)布時(shí)間:2024/10/8 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 word 宏 实例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

這個(gè)宏的基本功能如下:對(duì)一個(gè)文件中的每行都進(jìn)行轉(zhuǎn)換。

轉(zhuǎn)換前:1?? ?1001??? aaa ?? aaa ?? 0

轉(zhuǎn)換后: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 With
??? 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 With
??????? Selection.find.Execute
??????? Selection.find.Execute
??????? With Selection.find
??????????? .Text = ","
??????????? .Replacement.Text = ","""
??????????? .Forward = True
??????????? .Wrap = wdFindContinue
??????? End With
??????? 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
??????? With Selection.find
??????????? .Text = ","
??????????? .Replacement.Text = ""","""
??????????? .Forward = True
??????????? .Wrap = wdFindContinue
??????? End With
??????? 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
??????? With Selection.find
??????????? .Text = ","
??????????? .Replacement.Text = ""","
??????????? .Forward = True
??????????? .Wrap = wdFindContinue
??????? End With
??????? 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
??? Next i
End Sub

參考了以下文檔,以下轉(zhuǎn)載:

Application對(duì)象

- - - - - - - - - - - - - - - - - - - -
(301) Application.ActivePrinter ‘獲取當(dāng)前打印機(jī)
(302) Application.Height '當(dāng)前應(yīng)用程序文檔的高度
(303) Application.Width ‘當(dāng)前應(yīng)用程序文檔的寬度
(304) Application.Build ‘獲取Word版本號(hào)和編譯序號(hào)
(305) Application.Caption ‘當(dāng)前應(yīng)用程序名
(306) Application.DefaultSaveFormat '返回空字符串,表示W(wǎng)ord文檔
(307) Application.DisplayRecentFiles '返回是否顯示最近使用的文檔的狀態(tài)
(308) Application.Documents.Count '返回當(dāng)前打開的文檔數(shù)
(309) Application.FontNames.Count ‘返回當(dāng)前可用的字體數(shù)
(310) Application.Left ‘返回當(dāng)前文檔的水平位置
(311) Application.MacroContainer.FullName '返回當(dāng)前文檔名,包括所在路徑
(312) Application.NormalTemplate.FullName '返回文檔標(biāo)準(zhǔn)模板名稱及所在位置
(313) Application.RecentFiles.Count '返回最近打開的文檔數(shù)目
(314) Application.System.CountryRegion '返回應(yīng)用程序所在的地區(qū)代碼
(315) Application.System.FreeDiskSpace ‘返回應(yīng)用程序所在磁盤可用空間
(316) Application.System.HorizontalResolution '返回顯示器的水平分辨率
(317) Application.System.VerticalResolution '返回顯示器的垂直分辨率
(318) Application.System.LanguageDesignation '返回系統(tǒng)所使用的語言
(319) Application.System.MathCoprocessorInstalled ‘返回系統(tǒng)是否安裝了數(shù)學(xué)協(xié)處理器
(320) Application.System.OperatingSystem ‘返回當(dāng)前操作系統(tǒng)名
(321) Application.System.ProcessorType '返回計(jì)算機(jī)處理器名
(322) Application.System.Version ‘返回操作系統(tǒng)的版本號(hào)
(323) Application.Templates.Count '返回應(yīng)用程序所使用的模板數(shù)
(324) Application.UserName '返回應(yīng)用程序用戶名
(325) Application.Version ‘返回應(yīng)用程序的版本號(hào)
- - - - - - - - - - - - - - - - - - - - - -
Documents/Document對(duì)象
- - - - - - - - - - - - - - - - - - - - - -
(326) ActiveDocument.AttachedTemplate.FullName '返回當(dāng)前文檔采用的模板名及模板所在位置
(327) ActiveDocument.Bookmarks.Count '返回當(dāng)前文檔中的書簽數(shù)
(328) ActiveDocument.Characters.Count '返回當(dāng)前文檔的字符數(shù)
(329) ActiveDocument.CodeName ‘返回當(dāng)前文檔的代碼名稱
(330) ActiveDocument.Comments.Count ‘返回當(dāng)前文檔中的評(píng)論數(shù)
(331) ActiveDocument.Endnotes.Count '返回當(dāng)前文檔中的尾注數(shù)
(332) ActiveDocument.Fields.Count '返回當(dāng)前文檔中的域數(shù)目
(333) ActiveDocument.Footnotes.Count ‘返回當(dāng)前文檔中的腳注數(shù)
(334) ActiveDocument.FullName '返回當(dāng)前文檔的全名及所在位置
(335) ActiveDocument.HasPassword '當(dāng)前文檔是否有密碼保護(hù)
(336) ActiveDocument.Hyperlinks.Count '返回當(dāng)前文檔中的鏈接數(shù)
(337) ActiveDocument.Indexes.Count '返回當(dāng)前文檔中的索引數(shù)
(338) ActiveDocument.ListParagraphs.Count '返回當(dāng)前文檔中項(xiàng)目編號(hào)或項(xiàng)目符號(hào)數(shù)
(339) ActiveDocument.ListTemplates.Count '返回當(dāng)前文檔中使用的列表模板數(shù)
(340) ActiveDocument.Paragraphs.Count '返回當(dāng)前文檔中的段落數(shù)
(341) ActiveDocument.Password=XXX '設(shè)置打開文件使用的密碼
(342) ActiveDocument.ReadOnly '獲取當(dāng)前文檔是否為只讀屬性
(343) ActiveDocument.Saved '當(dāng)前文檔是否被保存
(344) ActiveDocument.Sections.Count '當(dāng)前文檔中的節(jié)數(shù)
(345) ActiveDocument.Sentences.Count ‘當(dāng)前文檔中的語句數(shù)
(346) ActiveDocument.Shapes.Count '當(dāng)前文檔中的形狀數(shù)
(347) ActiveDocument.Styles.Count '當(dāng)前文檔中的樣式數(shù)
(348) ActiveDocument.Tables.Count ‘當(dāng)前文檔中的表格數(shù)
(349) ActiveDocument.TablesOfAuthorities.Count ‘返回當(dāng)前文檔中的引文目錄數(shù)
(350) ActiveDocument.TablesOfAuthoritiesCategories.Count ‘返回當(dāng)前文檔中引文目錄類別數(shù)
(351) ActiveDocument.TablesOfContents.Count ‘返回當(dāng)前文檔中的目錄數(shù)
(352) ActiveDocument.TablesOfFigures.Count '返回當(dāng)前文檔中的圖表目錄數(shù)
- - - - - - - - - - - - - - - - - - - - - -
Paragraphs/Paragraph對(duì)象
- - - - - - - - - - - - - - - - - - - - - -
(353) Selection.Paragraphs.Count '返回所選區(qū)域的段落數(shù)
(354) Selection.Paragraphs.First '返回所選區(qū)域中的第一段
(355) ActiveDocument.Paragraphs(1).LeftIndent '返回當(dāng)前文檔中第一段的左縮進(jìn)值
(356) ActiveDocument.Paragraphs(1).LineSpacing '返回當(dāng)前文檔中第一段的行距
(357) ActiveDocument.Paragraphs(1).OutlineLevel? ‘返回或設(shè)置當(dāng)前文檔中第一段的大綱級(jí)別
(358) ActiveDocument.Paragraphs(1).RightIndent ‘返回當(dāng)前文檔中第一段的右縮進(jìn)量
(359) ActiveDocument.Paragraphs(1).SpaceBefore '返回當(dāng)前文檔中第一段的段前間距
(360) ActiveDocument.Paragraphs(1).SpaceAfter ‘返回當(dāng)前文檔中第一段的段后間距
(361) ActiveDocument.Paragraphs(1).Range.Text '返回當(dāng)前文檔中第一段的內(nèi)容
(362) ActiveDocument.Paragraphs(1).Range.Style.NameLocal '返回當(dāng)前文檔中第一段應(yīng)用的樣式名
(363) ActiveDocument.Paragraphs(1).Range.Style.Descrīption '返回當(dāng)前文檔中第一段所應(yīng)用樣式的詳細(xì)描述
(364) ActiveDocument.Paragraphs(1).Range.Style.Font.Name '返回當(dāng)前文檔中第一段所應(yīng)用樣式的字體名
(365) ActiveDocument.Paragraphs(1).Range.Style.Font.NameFarEast '返回或設(shè)置一種東亞字體名
(366) ActiveDocument.Paragraphs(1).Range.Style.Font.Size '返回或設(shè)置當(dāng)前文檔中第一段所應(yīng)用樣式的字體大小
(367) ActiveDocument.Paragraphs(1).Range.Style.Font.Spacing '返回或設(shè)置字符間距
(368) Selection.Words.Count '所選區(qū)域的字?jǐn)?shù)
- - - - - - - - - - - - -
Sentences對(duì)象
- - - - - - - - - - - - -
(369) Selection.Sentences.Item(1) '所選區(qū)域中的第一句的內(nèi)容
- - - - - - - - - -
Words對(duì)象
- - - - - - - - - -
(371) ActiveDocument.Words(1).Select '選擇當(dāng)前文檔中的第一個(gè)詞
(372) ActiveDocument.Range.Words(1).InsertAfter "我愛你!" '在當(dāng)前文檔中的第一個(gè)詞后插入“我愛你”
- - - - - - - - - - - - -
Characters對(duì)象
- - - - - - - - - - - - -
(373) Selection.Characters.Count '當(dāng)前文檔中所選區(qū)域的字符數(shù)
(374) ActiveDocument.Paragraphs(1).Range.InsertParagraphAfter '在當(dāng)前文檔的第一段之后插入一個(gè)新段落
- - - - - - - - - - - - - - - - - -
Sections/Section對(duì)象
- - - - - - - - - - - - - - - - - -
(375) ActiveDocument.Sections.First '當(dāng)前文檔的第一節(jié)
(376) ActiveDocument.Sections.First.PageSetup.BottomMargin '當(dāng)前文檔第一節(jié)所在頁的底邊距
(377) ActiveDocument.Sections.First.PageSetup.LeftMargin '當(dāng)前文檔第一節(jié)所在頁的左邊距
(378) ActiveDocument.Sections.First.PageSetup.RightMargin '當(dāng)前文檔第一節(jié)所在頁的右邊距
(379) ActiveDocument.Sections.First.PageSetup.TopMargin '當(dāng)前文檔第一節(jié)所在頁的頂邊距
(380) ActiveDocument.Sections.First.PageSetup.PaperSize '返回或設(shè)置當(dāng)前文檔第一節(jié)所在頁的大小
(381) ActiveDocument.Sections.First.PageSetup.PageHeight '返回或設(shè)置當(dāng)前文檔第一節(jié)所在頁的高度
(382) ActiveDocument.Sections.First.PageSetup.PageWidth '返回或設(shè)置當(dāng)前文檔第一節(jié)所在頁的寬度
(383) ActiveDocument.Sections.Add Range:=myRange '在當(dāng)前文檔中添加新節(jié)
(384) ActiveDocument.Sections.Item(2) '當(dāng)前文檔中的第二節(jié)
(385) ActiveDocument.Sections.Last.Range.InsertAfter "文檔結(jié)束!" '在當(dāng)前文檔中最后一節(jié)的結(jié)尾添加文字“文檔結(jié)束!”
- - - - - - - - - -
Range對(duì)象
- - - - - - - - - -
(386) ActiveDocument.Range(Start:=0, End:=10) '表示當(dāng)前文檔前10個(gè)字符所組成的一個(gè)Range對(duì)象
(387) Set myRange = ActiveDocument.Range( _
??? Start:=ActiveDocument.Paragraphs(2).Range.Start, _
End:=ActiveDocument.Paragraphs(4).Range.End) '將當(dāng)前文檔第2段至第4段設(shè)置為一個(gè)Range對(duì)象
(388) ActiveDocument.Paragraphs(1).Range.Copy? '復(fù)制當(dāng)前文檔中的第一段
(389) Selection.Copy
Documents.Add.Content.Paste '復(fù)制所選內(nèi)容到新文檔中
(390) ActiveDocument.Bookmarks("Book1").Copy Name:="Book2" '將Book2書簽復(fù)制Book1書簽標(biāo)記的位置
(391) Selection.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=4 '將所選內(nèi)容移至文檔中的第4行
(392) Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext '將所選內(nèi)容移至下一個(gè)表格的第1個(gè)單元格
(393) Selection.Range.AutoFormat '為所選內(nèi)容套用格式
(394) ActiveDocument.Content.Font.Name = "Arial" '將當(dāng)前文檔的字體設(shè)置為斜體
(395) ActiveDocument.Content.Select
Selection.Delete '將當(dāng)前文檔中的內(nèi)容刪除
- - - - -
其它
- - - - -
(396) Documents.Add '添加一個(gè)新文檔
(397) Set myTable = ActiveDocument.Tables.Add(Selection.Range, 2, 2) '在當(dāng)前文檔所選區(qū)域添加一個(gè)2行2列的表格
(398) Open "C:"my.txt" For Input As #1 '打開一個(gè)用于輸入的文件并令其編號(hào)為1
(399) Line Input #1, TextLine '讀取被打開用于輸入且編號(hào)為1的文件
(400) Close #1? '關(guān)閉編號(hào)為1的文件

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/strinkbug/archive/2009/03/26/1422412.html

總結(jié)

以上是生活随笔為你收集整理的word 宏 实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。