2011-12-06 147 views
-1

我試圖將數據從excel文件複製到一個word文件作爲截圖。但問題是粘貼的數據非常小。有沒有辦法在複製或粘貼後增加尺寸?以下是我寫的代碼。提前致謝。如何通過VBA將數據從Excel複製到Word文檔?

Range("A" & startRow & ":G" & endRow).Select 
    Selection.Copy 

    With WordApp 
     .Selection.PasteSpecial Link:=False, DisplayAsIcon:=False, _ 
      DataType:=wdPasteMetafilePicture, Placement:=wdInLine 
     .Selection.TypeParagraph 

     .Selection.Orientation = wdTextOrientationVertical 
    End With 

回答

2

您複製之後,因爲它是你建造的最後形狀,您可以調整你的形狀。

下面是代碼,您可以添加:

Dim oShape As Word.InlineShape 
Dim i As Integer 
i = ActiveDocument.InlineShapes.Count 
' set oShape to the LAST inlineshape 
Set oShape = ActiveDocument.InlineShapes(i) 
    With oShape 
' examples only - scale to 90% 
     .ScaleHeight = 90 
     .ScaleWidth = 90 
     ' * * * etc etc etc * * * * 
    End With 
Set oShape = Nothing 

而且可以簡化您的Excel代碼,因爲你沒有複製前選擇:

Range("A" & startRow & ":G" & endRow).Copy 

足夠

+0

+ 1,特別是因爲OP doensn似乎不關心他的問題的答案... – aevanko

+0

謝謝Issun :)。其實,我想知道我們如何調整形狀......我發現它雖然 – JMax

+0

是的,我從來不知道,所以這是非常整潔。 :) – aevanko

相關問題