首页 > 解决方案 > 如何调整 Word 文档中的图像大小?

问题描述

在 Excel 中,打开 Word 文档,将图像粘贴到当前位置,然后调整其大小。

我尝试在InlineShapes.AddPicture.

这是插入图像的代码。

Sub CreateWordDocWithPicture()
    Dim wdApp As Word.Application
    Dim wdDoc As Word.Document
    DocDirectory = "C:\Documents\"
    Set wdApp = CreateObject("Word.Application") 'Create an instance of word
    Set wdDoc = wdApp.Documents.Open(DocDirectory & "Template.docx", ReadOnly:=True) 
    'Open word file
    wdApp.Visible = True
    wdApp.Selection.InlineShapes.AddPicture Filename:=DocDirectory & "Image.jpg", LinkToFile:=False, SaveWithDocument:=True
        
End Sub

标签: excelvbaimagems-wordresize

解决方案


例如:

Sub CreateWordDocWithPicture()
Dim wdApp As New Word.Application, wdDoc As Word.Document, wdIshp As Word.InlineShape
Const DocDirectory As String = "C:\Documents\"
With wdApp
  .Visible = True
  'Open word file
  Set wdDoc = .Documents.Open(DocDirectory & "Template.docx", ReadOnly:=True)
  With wdDoc
    'Insert the image
    Set wdIshp = .InlineShapes.AddPicture(FileName:=DocDirectory & "Image.jpg", _
      LinkToFile:=False, SaveWithDocument:=True, Range:=.Range.Characters.Last)
    'Resize the image
    With wdIshp
      .LockAspectRatio = True
      .Height = InchesToPoints(1.5)
    End With
  End With
End With
End Sub

推荐阅读