如何将图像插入VBA中的导出报表

时间:2015-01-05 17:00:05

标签: excel vba excel-vba

我正在尝试插入图像作为Excel VBA中分析生成的报告的一部分。该报告是word文档格式(.doc)

导出报告的功能如下所示,这对我来说很好。唯一的问题是我无法将图像放入报告中。

Function FnExportToWordDoc()
Dim objWord
Dim objDoc
Dim pctCompl As Single
Dim objSelection

msg = msg & "STRESS DUE TO SUSTAINED LOAD TEST " & sustainedtest & vbNewLine
msg = msg & " " & vbNewLine
msg = msg & " The design for occassional load require that " & occtest & "<" & occright &       vbNewLine
msg = msg & " " & vbNewLine
msg = msg & " Allowable stress due to dead weight  " & Sallsus & "psi" & vbNewLine
msg = msg & " " & vbNewLine
msg = msg & "STRESS DUE TO OCCASIONAL LOAD TEST " & occtestmsg & vbNewLine
msg = msg & " " & vbNewLine   
msg = msg & "I want an image here"

reportdrs = Mypath.reportpath
reportname = Myname.reportname
reportdr = reportdrs & "\" & reportname

Set objWord = CreateObject("Word.Application")

Set objDoc = objWord.Documents.Add

objWord.Visible = True

Set objSelection = objWord.Selection

objSelection.TypeText (msg)

objDoc.SaveAs (reportdr)

msgre = "The report has been saved here " & reportdr & vbNewLine

Title = "Report Generated"
MsgBox msgre, vbOKOnly, Title


End Function

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

Sub Example1()
  Selection.InlineShapes.AddPicture FileName:= _
    "D:\Stuff\Business\Temp\SP_A0155.jpg", LinkToFile:=False, _
    SaveWithDocument:=True
End Sub

快速Google搜索是否将图片插入到文字中,并在http://software-solutions-online.com/2014/05/13/word-vba-insert-images/

找到了上述内容
相关问题