1、 2、在Word文档中插入和导出图片对象vbview plaincopy1. 先引用MicrosoftWord11.0ObjectLibrary2. OptionExplicit3. 4. DimWordAppAsWord.Application创建Word应用程序5. 6. PrivateSubCommand1_Click()7. OnErrorGoToErrhandler8. CommonDialog1.Filter=Word(*.Doc)|*.Doc|AllFile(*.*)|*.*9. CommonDialog1.FilterIndex=110. CommonDialog1.ShowO
2、pen11. SetWordApp=NewWord.Application实例化12. WordApp.Documents.OpenCommonDialog1.FileName打开Word文件13. WordApp.Visible=True显示OfficeWord界面14. 或者Application.Visible=True15. WordApp.DisplayAlerts=False不提示保存对话框16. WordApp.Selection.EndKeyUnit:=wdStory将光标移到文档末尾,在文本后面插入图片对象17. Selection.TypeTextText:=我的图片图片的
3、标题名称18. 19. 插入图片对象20. Selection.InlineShapes.AddPictureFileName:=C:CommandPicture.jpg,LinkToFile:=False,SaveWithDocument:=True21. Selection.MoveLeftUnit:=wdCharacter,Count:=1,Extend:=wdExtend22. Selection.InlineShapes(1).ConvertToShape.Select23. Selection.ShapeRange.Fill.Visible=msoFalse24. Selectio
4、n.ShapeRange.Fill.Transparency=0#25. Selection.ShapeRange.Line.Weight=0.7526. Selection.ShapeRange.Line.DashStyle=msoLineSolid27. Selection.ShapeRange.Line.Style=msoLineSingle28. Selection.ShapeRange.Line.Transparency=0#29. Selection.ShapeRange.Line.Visible=msoFalse30. Selection.ShapeRange.LockAspec
5、tRatio=msoTrue31. Selection.ShapeRange.Height=361.432. Selection.ShapeRange.Width=481.633. Selection.ShapeRange.PictureFormat.Brightness=0.534. Selection.ShapeRange.PictureFormat.Contrast=0.535. Selection.ShapeRange.PictureFormat.ColorType=msoPictureAutomatic36. Selection.ShapeRange.PictureFormat.Cr
6、opLeft=0#37. Selection.ShapeRange.PictureFormat.CropRight=0#38. Selection.ShapeRange.PictureFormat.CropTop=0#39. Selection.ShapeRange.PictureFormat.CropBottom=0#40. Selection.ShapeRange.RelativeHorizontalPosition=wdRelativeHorizontalPositionColumn41. Selection.ShapeRange.RelativeVerticalPosition=wdR
7、elativeVerticalPositionPage42. Selection.ShapeRange.Left=wdShapeCenter43. Selection.ShapeRange.Top=wdShapeCenter44. Selection.ShapeRange.LockAnchor=False45. Selection.ShapeRange.WrapFormat.AllowOverlap=True46. Selection.ShapeRange.WrapFormat.Side=wdWrapBoth47. Selection.ShapeRange.WrapFormat.Distanc
8、eTop=CentimetersToPoints(0)48. Selection.ShapeRange.WrapFormat.DistanceBottom=CentimetersToPoints(0)49. Selection.ShapeRange.WrapFormat.DistanceLeft=CentimetersToPoints(0.32)50. Selection.ShapeRange.WrapFormat.DistanceRight=CentimetersToPoints(0.32)51. Selection.ShapeRange.WrapFormat.Type=352. Selec
9、tion.ShapeRange.ZOrdermsoSendBehindText设置图片为衬托于文字下方53. 54. 判断文档中是否存在图片对象55. IfActiveDocument.Shapes.Count+ActiveDocument.InlineShapes.Count0Then56. 取得图片的2种方法57. 58. 第1种方法:用下面命令将文件另存为网页格式的文件,文件夹“MyWord.files”将保存Word文档中所有的图片59. 这种方法对所有的Word版本均适用60. ActiveDocument.SaveAsc:MyWord.htm,wdFormatHTML保存为网页格式
10、61. 62. 第2种方法:引用ADO对象库,将所有的图片保存在数据库中,然后可以一张一张地显示出来63. 64. 另外:65. 如果Word文档是docx格式的,那可以按这个办法解决:66. .docx格式的文件本质上是一个ZIP压缩文件,.docx格式文件的主要内容是保存为XML格式的,但文件并非直接保存于磁盘。67. 它是保存在一个ZIP文件中,然后取扩展名为.docx。我们只需要用解压软件比如:WinZIP、WinRAR或者7ZIP等软件进行解压就可以了。68. 方法有两种,一种是将.docx后缀名修改为.zip后缀名;另一个方法就是打开WinZIP然后,选择此文档即可。69. 图片资源文件都被保存在wordmedia文件夹中。70. 71. Else72. Debug.PrintWord文档中不存在图片对象!73. EndIf74. 75. Errhandler:76. ExitSub77. EndSub78. 79. PrivateSubForm_Unload(CancelAsInteger)80. OnErrorResumeNext81. WordApp.Quit82. SetWordApp=Nothing83. EndSub