简体   繁体   English

如何复制 excel 中的范围,然后使用宏调整大小并粘贴到 word 中

[英]How to copy a range in excel and then resize and paste in word with a macro

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

The code is actualy working but I'm not capable of applying the resize of the image that I want.该代码实际上是有效的,但我无法应用我想要的图像大小。 Do you guys know a way that I can resize the picture that i'm pasting in Word coming form a range in Excel?你们知道一种方法可以调整我在 Word 中粘贴的图片的大小,形成 Excel 的范围吗?

Try:尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM