現在需要用vb將一張圖片和excel中的圖表粘貼在word檔案中,要求的格式從上到下為圖片,excel圖表1,excel圖表2,excel圖表3
當程式呼叫word2007時,格式和順序正常。但是當呼叫word2010時,圖片跑到了檔案末尾,求大神指點。
工程參考的 Microsoft excel 14.0 object library和 Microsoft word 14.0 object library
附上相關代碼
wordApp.Selection.TypeText Chr(13)
wordApp.Selection.ClearFormatting
wordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
wordDoc.InlineShapes.AddPicture workpath & "\質量直徑繪圖.bmp" '在word報告中粘貼
wordApp.Selection.TypeText Chr(13)
wordApp.Selection.TypeText "圖1 軸系質量直徑繪圖"
wordApp.Selection.TypeText Chr(13)
tempxlWorkbook.Worksheets("Sheet1").ChartObjects(1).Activate
tempxlWorkbook.Worksheets("Sheet1").ChartObjects(1).Chart.CopyPicture
wordApp.Selection.ClearFormatting
wordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
wordApp.Selection.Paste '在word報告中粘貼揚度曲線圖
wordApp.Selection.TypeText Chr(13)
wordApp.Selection.TypeText "圖2 軸系各節點揚度曲線"
wordApp.Selection.TypeText Chr(13)
wordApp.Selection.TypeText Chr(13)
tempxlWorkbook.Worksheets("Sheet1").ChartObjects(2).Activate
tempxlWorkbook.Worksheets("Sheet1").ChartObjects(2).Chart.CopyPicture
wordApp.Selection.ClearFormatting
wordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
wordApp.Selection.Paste '在word報告中粘貼彎應力曲線圖
wordApp.Selection.TypeText Chr(13)
wordApp.Selection.TypeText "圖3 軸系各節點彎應力曲線"
wordApp.Selection.TypeText Chr(13)
tempxlWorkbook.Worksheets("Sheet1").ChartObjects(3).Activate
tempxlWorkbook.Worksheets("Sheet1").ChartObjects(3).Chart.CopyPicture
wordApp.Selection.ClearFormatting
wordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
wordApp.Selection.Paste '在word報告中粘貼彎應力曲線圖
wordApp.Selection.TypeText Chr(13)
wordApp.Selection.TypeText "圖4 軸系各節點彎矩曲線"
uj5u.com熱心網友回復:
2007和2010得參考不同版本的object library,我覺得。uj5u.com熱心網友回復:
2007和2010得參考不同版本的object library,我覺得也是
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/99648.html
標籤:VBA
