vb控制word實(shí)例2.doc_第1頁(yè)
vb控制word實(shí)例2.doc_第2頁(yè)
vb控制word實(shí)例2.doc_第3頁(yè)
vb控制word實(shí)例2.doc_第4頁(yè)
vb控制word實(shí)例2.doc_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、返回Word文檔的段落文字,控制分頁(yè),設(shè)置頁(yè)眉和頁(yè)腳vbview plaincopy1. 先引用MicrosoftWord11.0ObjectLibrary2. OptionExplicit3. 4. DimWordAppAsWord.Application創(chuàng)建Word應(yīng)用程序5. 6. PrivateSubCommand1_Click()7. DimiAsLong8. OnErrorGoToErrhandler9. CommonDialog1.Filter=Word(*.Doc)|*.Doc|AllFile(*.*)|*.*10. CommonDialog1.FilterIndex=111. CommonDialog1.ShowOpen12. SetWordApp=NewWord.Application實(shí)例化13. WordApp.Documents.OpenCommonDialog1.FileName打開(kāi)Word文件14. WordApp.Visible=True顯示OfficeWord界面15. 或者Application.Visible=True16. WordApp.DisplayAlerts=False不提示保存對(duì)話框17. 18. 返回段落文字,返回的段落文字在文本框控件中19. Text1.Text=20. Fori=1ToActiveDocument.Paragraphs.Count21. Text1.Text=Text1.Text&(ActiveDocument.Paragraphs(i).Range.Text&vbCrLf&vbCrLf)22. Next23. 24. 控制分頁(yè)25. WordApp.Selection.EndKeyunit:=wdStory將光標(biāo)移到文檔末尾26. WordApp.Selection.InsertBreakwdPageBreak在文檔末尾插入一頁(yè)27. 28. 設(shè)置圖片格式的頁(yè)眉29. IfActiveWindow.View.SplitSpecialwdPaneNoneThen30. ActiveWindow.Panes(2).Close31. EndIf32. IfActiveWindow.ActivePane.View.Type=wdNormalViewOrActiveWindow.ActivePane.View.Type=wdOutlineViewThen33. ActiveWindow.ActivePane.View.Type=wdPrintView34. EndIf35. ActiveWindow.ActivePane.View.SeekView=wdSeekCurrentPageHeader36. Selection.InlineShapes.AddPictureFileName:=F:資料MyPictures2013年元旦.gif,LinkToFile:=False,SaveWithDocument:=True加載一圖片文件作為頁(yè)眉37. Selection.ParagraphFormat.Alignment=wdAlignParagraphLeft38. ActiveWindow.ActivePane.View.SeekView=wdSeekMainDocument39. 40. 設(shè)置文本格式的頁(yè)眉41. IfActiveWindow.View.SplitSpecialwdPaneNoneThen42. ActiveWindow.Panes(2).Close43. EndIf44. IfActiveWindow.ActivePane.View.Type=wdNormalViewOrActiveWindow.ActivePane.View.Type=wdOutlineViewThen45. ActiveWindow.ActivePane.View.Type=wdPrintView46. EndIf47. ActiveWindow.ActivePane.View.SeekView=wdSeekCurrentPageHeader48. Selection.TypeTextText:=辦公室常用工具49. ActiveWindow.ActivePane.View.SeekView=wdSeekMainDocument50. 51. 隱藏頁(yè)眉的橫線52. WordApp.ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Borders(wdBorderBottom).Visible=False53. 54. 取得頁(yè)眉的內(nèi)容55. Debug.PrintWordApp.ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Text獲取WORD第一節(jié)的頁(yè)眉的文字內(nèi)容56. 57. 58. 設(shè)置頁(yè)腳59. IfActiveWindow.View.SplitSpecialwdPaneNoneThen60. ActiveWindow.Panes(2).Close61. EndIf62. IfActiveWindow.ActivePane.View.Type=wdNormalViewOrActiveWindow.ActivePane.View.Type=wdOutlineViewThen63. ActiveWindow.ActivePane.View.Type=wdPrintView64. EndIf65. ActiveWindow.ActivePane.View.SeekView=wdSeekCurrentPageHeader66. IfSelection.HeaderFooter.IsHeader=TrueThen67. ActiveWindow.ActivePane.View.SeekView=wdSeekCurrentPageFooter68. Else69. ActiveWindow.ActivePane.View.SeekView=wdSeekCurrentPageHeader70. EndIf71. Selection.TypeTextText:=2013年設(shè)置頁(yè)腳72. Selection.Fields.AddRange:=Selection.Range,Type:=wdFieldNumPages73. ActiveWindow.ActivePane.View.SeekView=wdSeekMainDocument74. 75. ActiveDocument.SaveAsc:MyWord.doc保存最后生成的word文檔76. 77. Errhandler:78. ExitSub79. EndSub80. 81. PrivateSubForm_Unload(CancelAsInteger)82. OnErrorResumeNext83. WordApp.Quit84. SetWordApp=Nothing85. EndSub 效果圖如下: 2、控制Word文檔中的文本框?qū)ο髒bview plaincopy1. 先引用MicrosoftWord11.0ObjectLibrary2. OptionExplicit3. 4. DimWordAppAsWord.Application創(chuàng)建Word應(yīng)用程序5. 6. PrivateSubCommand1_Click()7. OnErrorGoToErrhandler8. CommonDialog1.Filter=MSOfficeWord(*.Doc)|*.Doc|AllFile(*.*)|*.*9. CommonDialog1.FilterIndex=110. CommonDialog1.ShowOpen11. SetWordApp=NewWord.Application實(shí)例化12. WordApp.Documents.OpenCommonDialog1.FileName打開(kāi)Word文件13. IfDocuments.Count=1Then14. Text1.Text=打開(kāi)的Word文件是:&ActiveDocument.Name&vbCrLf&vbCrLf15. EndIf16. WordApp.Visible=True顯示OfficeWord界面17. 或者Application.Visible=True18. WordApp.DisplayAlerts=False不提示保存對(duì)話框19. 20. WordApp.Selection.EndKeyunit:=wdStory將光標(biāo)移到文檔末尾21. WordApp.Selection.Font.Bold=122. WordApp.Selection.Font.Name=黑體23. WordApp.Selection.Font.Size=1824. WordApp.Selection.TypeTextText:=在Word文件中插入文本框?qū)ο?5. WordApp.Selection.ParagraphFormat.Alignment=Word.WdParagraphAlignment.wdAlignParagraphCenter居中顯示26. 27. 創(chuàng)建文本框?qū)ο?座標(biāo)(100,100),寬度200,高度20028. WithActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal,100,100,400,300).Fill29. .Transparency=1設(shè)置透明色30. .ForeColor=vbRed設(shè)置前景顏色31. .UserPicture(F:資料MyPictures758254_960x1000_0.jpg)設(shè)置文本框?qū)ο蟮谋尘皥D片32. EndWith33. ActiveDocument.Shapes(1).TextFrame.TextRange.Text=這是一個(gè)美女給文本框賦值34. ActiveDocument.Shapes(1).Line.Transparency=1設(shè)置透明邊框線條35. 36. 再創(chuàng)建一個(gè)透明背景的文本框?qū)ο?7. WithActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal,100,400,400,300).Fill38. .Transparency=1設(shè)置透明色背景39. .ForeColor=vbRed設(shè)置前景顏色40. EndWith41. ActiveDocument.Shapes(2).TextFrame.TextRange.Text=這是一個(gè)透明背景的文本框給文本框賦值42. ActiveDocument.Shapes(2).Line.Transparency=1設(shè)置透明邊框線條43. 44. 下面是獲取文本框?qū)ο蟮膬?nèi)容45. DimiAsLong46. Fori=1ToActiveDocument.Shapes.Count47. Text1.Text=Text1.Text&(第&i&個(gè)文本框的內(nèi)容:&ActiveDocument.Shapes(i).TextFrame.TextRange.Text&vbCrLf)48. Next49. 50. ActiveDocument.SaveAsc:MyWord.doc保存最后生成的word文檔51. 52. Errhandler:53. ExitSub54. EndSub55. 56. PrivateSubForm_Unload(CancelAsInteger)57. OnErrorResumeNext58. WordApp.Quit59. SetWordApp=Nothing60. EndSub 效果圖如下: 3、在Word文檔中設(shè)置Excel風(fēng)格的頁(yè)碼vbview plaincopy1. 先引用MicrosoftWord11.0ObjectLibrary2. OptionExplicit3. 4. DimWordAppAsWord.Application創(chuàng)建Word應(yīng)用程序5. DimWordDocAsWord.Document創(chuàng)建Word文檔對(duì)象6. 7. PrivateSubCommand1_Click()8. DimiAsLong9. OnErrorGoToErrhandler10. CommonDialog1.Filter=Word(*.Doc)|*.Doc|AllFile(*.*)|*.*11. CommonDialog1.FilterIndex=112. CommonDialog1.ShowOpen13. SetWordApp=NewWord.Application實(shí)例化14. SetWordDoc=WordApp.Documents.Open(CommonDialog1.FileName)選擇并打開(kāi)Word文件15. WordApp.Visible=True顯示OfficeWord界面16. 或者Application.Visible=True17. WordApp.DisplayAlerts=False不提示保存對(duì)話框18. 19. 設(shè)置Word文檔第一頁(yè)頁(yè)碼20. DimWordRangeAsRange21. SetWordRange=WordApp.ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range22. 23. WithWordRange24. .InsertAfter第25. .Font.Size=1426. .CollapseDirection:=wdCollapseEnd27. 28. 插入頁(yè)碼域29. .Fields.AddRange:=WordRange,Type:=wdFieldEmpty,Text:=PAGE*Arabic,PreserveFormatting:=True30. .Expandunit:=wdWord31. .InsertAfter頁(yè)32

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論