2016-04-06 94 views
0

我編寫了一個宏,用於從Excel文件生成調查問卷Word文檔。
Excel的行看起來是這樣的(圖像是細胞的評論裏):使用VBA將位圖從Excel單元格的註釋複製到Word文檔

excel db

我想在Word文檔看起來像這樣:

word result

到目前爲止,我管理以創建問題,但沒有使用此代碼的圖片:

... open app and document and get the relevant styles... 

With wSelection 
    .Style = Question 
    .TypeText vbCrLf 

    .Style = QuestionBody 
    .TypeText Range("A" & row).Value & vbCrLf 


    'Here I need to copy the bitmap 
    'How? 


    .Style = Answer 
    For Col = Asc("B") To Asc("E") 
     answerOption = Range(Chr(Col) & row).Value 
     .TypeText answerOption & vbCrLf 
    Next Col 

    .Style = wDoc.Styles(wdStyleNormal) 
End With 

我找不到如何將註釋中的位圖複製到word文檔。 我試過使用:

Range("A" & row).Comment.Shape.CopyPicture 
.PasteSpecial datatype:=wdPasteBitmap 
'or just .Paste 

但它沒有奏效。

+0

能否請您就如何爲「不工作」的更多細節。你有錯誤嗎?沒有複製?或者是剪貼板上的東西,但在Word中粘貼會導致問題? –

+0

@CindyMeister什麼都沒有發生。 CopyPicture和PasteSpecial命令沒有引發任何錯誤,但位圖沒有出現在word文檔中。 – marcelo13k

回答

0

試試這個

Range("A" & row).Comment.Shape.CopyPicture.CopyPicture xlScreen, xlBitmap 
With wSelection 
    .PasteSpecial datatype:=wdPasteBitmap 
    ... 
End With 
+0

它產生與沒有'xlScreen,xlBitmap'相同的結果,這意味着,不復制位圖,不會引發錯誤(當然,我認爲'CopyPicture' dup在您的答案中只是一個錯字) – marcelo13k

相關問題