我创建了以下代码,用于将Excel工作表中的嵌入式Word文档导出到工作簿的路径:
Private Sub Export()
Dim sh As Shape
Dim objWord As Object 'Word.Document
Dim objOLE As OLEObject
Set sh = Sheet5.Shapes("Object 1")
sh.OLEFormat.Activate
Set objOLE = sh.OLEFormat.Object
Set objWord = objOLE.Object
objWord.Application.Visible = False
objWord.SaveAs2 Filename:=ActiveWorkbook.Path & "\MyTemplate.docx", FileFormat:= _
wdFormatDocumentDefault
objWord.Application.Quit
End Sub
它在Excel 2013上完美运行,但是当我尝试在Excel 2007上的办公室中运行它时,它给了我一个运行时错误''' "对象不支持此属性或方法"在objWord.SaveAs2 Filename:=ActiveWorkbook.Path & "\MyTemplate.docx", FileFormat:= wdFormatDocumentDefault
行
尝试过定义objWord,但没有运气。有什么建议吗?