2、在Word文档中插入和导出图片对象
[vb] view plaincopy
1.'先引用Microsoft Word 11.0 Object Library
2.Option Explicit
3.
4.Dim WordApp As Word.Application '创建Word应用程序
5.
6.Private Sub Command1_Click()
7. On Error GoTo Errhandler
8. CommonDialog1.Filter = "Word(*.Doc)|*.Doc|AllFile(*.*)|*.*"
9. CommonDialog1.FilterIndex = 1
10. CommonDialog1.ShowOpen
11. Set WordApp = New Word.Application '实例化
12. WordApp.Documents.Open CommonDialog1.FileName '打开Word文件
13. WordApp.Visible = True '显示 Office Word 界面
14. '或者Application.Visible = True
15. WordApp.DisplayAlerts = False '不提示保存对话框
16. WordApp.Selection.EndKey Unit:=wdStory '将光标移到文档末尾,在文本后面插入图片对象
17. Selection.TypeText Text:="我的图片" '图片的标题名称
18.
19. '插入图片对象
20. Selection.InlineShapes.AddPicture FileName:="C:\CommandPicture.jpg", LinkToFile:=Fals
e, SaveWithDocument:=True
21. Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
22. Selection.InlineShapes(1).ConvertToShape.Select
23. Selection.ShapeRange.Fill.Visible = msoFalse
24. Selection.ShapeRange.Fill.Transparency = 0#
25. Selection.ShapeRange.Line.Weight = 0.75
26. Selection.ShapeRange.Line.DashStyle = msoLineSolid
27. Selection.ShapeRange.Line.Style = msoLineSingle
28. Selection.ShapeRange.Line.Transparency = 0#
29. Selection.ShapeRange.Line.Visible = msoFalse
30. Selection.ShapeRange.LockAspectRatio = msoTrue
31. Selection.ShapeRange.Height = 361.4
32. Selection.ShapeRange.Width = 481.6
33. Selection.ShapeRange.PictureFormat.Brightness = 0.5
34. Selection.ShapeRange.PictureFormat.Contrast = 0.5
35. Selection.ShapeRange.PictureFormat.ColorType = msoPictureAutomatic
36. Selection.ShapeRange.PictureFormat.CropLeft = 0#
37. Selection.ShapeRange.PictureFormat.CropRight = 0#
38. Selection.ShapeRange.PictureFormat.CropTop = 0#
39. Selection.ShapeRange.PictureFormat.CropBottom = 0#
40. Selection.ShapeRange.RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn