【问题标题】:How to copy a range in excel and then resize and paste in word with a macro如何在excel中复制一个范围,然后使用宏调整大小并粘贴到word中
【发布时间】:2020-05-18 17:08:02
【问题描述】:
Sub CopyToWord()

    Dim objWord As New Word.Application


    'copying the range that I want to paste in Word
    With ThisWorkbook.Worksheets("grid_copy")
        .Range("b1:AA42").CopyPicture xlScreen

    End With

    'pasting the picture in a new Word document
    With objWord
        .Documents.Add
        .Selection.Paste
        .Selection.ShapeRange.Height = 651
        .Selection.ShapeRange.Width = 500
        'Those two lines don't work to resize the picture that i'm pasting in word
        .Visible = True
    End With


End Sub

代码实际上可以工作,但我无法应用我想要的图像大小。你们知道一种方法可以调整我在 Word 中粘贴的图片的大小吗?

【问题讨论】:

    标签: excel vba ms-word resize export-to-word


    【解决方案1】:

    试试:

    Sub CopyToWord()
    'copying the range that I want to paste in Word
    ThisWorkbook.Worksheets("grid_copy").Range("b1:AA42").CopyPicture xlScreen
    'pasting the picture in a new Word document
    Dim wdApp As New Word.Application, wdDoc As Word.Document, wdImg As Word.InlineShape
    With wdApp
      .Visible = True
      .ScreenUpdating = False
      Set wdDoc = .Documents.Add
      With wdDoc
        .Range.Paste
        Set wdImg = .InlineShapes(1)
        With wdImg
          .Height = 651
          .Width = 500
        End With
      End With
      .ScreenUpdating = True
    End With
    End Sub
    

    【讨论】:

    • 谢谢你的回答,我想我们已经很亲近了!但是我在指向 .Paste 的“Set wdImg = .Range.Paste”这一行上收到错误“函数或变量预期”... 你知道为什么吗?
    • 不确定那里发生了什么。试试修改后的代码。
    猜你喜欢
    • 2022-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多