我需要将excel单元格内容导出到嵌入式word文档(嵌入在同一excel文件中)中的特定书签。这是我写的代码:
Sub Provareport()
Dim ws As Worksheet
Dim wd As Object
Dim oEmbFile As Object
Set ws = ThisWorkbook.Worksheets("Modello")
Set wd = CreateObject("Word.application")
'opening the embedded document
Application.DisplayAlerts = False
Set oEmbFile = ThisWorkbook.Sheets("BANCHE").OLEObjects("Reword")
oEmbFile.Verb Verb:=xlPrimary
Set oEmbFile = Nothing
Application.DisplayAlerts = True
With wd.ActiveDocument
.Bookmarks("Denominazione").Range.Text = ws.Range("G13").Value
.Bookmarks("SNDG").Range.Text = ws.Range("F13").Value
.Bookmarks("Organo_deliberante").Range.Text = ws.Range("I13").Value
.Bookmarks("Headline").Range.Text = ws.Range("B80").Value
.Bookmarks("Attivo").Range.Text = ws.Range("B81").Value
.Bookmarks("Passivo").Range.Text = ws.Range("B90").Value
.Bookmarks("LCRNSFR").Range.Text = ws.Range("B93").Value
.Bookmarks("Patrimonializzazione").Range.Text = ws.Range("B94").Value
.Bookmarks("Patrimonio2").Range.Text = ws.Range("B95").Value
.Bookmarks("Conto_economico").Range.Text = ws.Range("B98").Value
.Bookmarks("Conto_economico2").Range.Text = ws.Range("B100").Value
.Bookmarks("Conto_economico3").Range.Text = ws.Range("B105").Value
.Bookmarks("Conto_economico4").Range.Text = ws.Range("B108").Value
End With
Set doc = Nothing
Set wd = Nothing
End Sub
当我运行代码时,它停在以下行:
With wd.ActiveDocument
,并出现以下错误:
“运行时错误'4248” 该命令不可用,因为没有打开任何文档。
但是,单词文档实际上是打开的。
有人可以帮我吗?
答案 0 :(得分:0)
然后尝试在声明部分
Dim wd As Word.Document
最后
Set oEmbFile = ThisWorkbook.Sheets("BANCHE").OLEObjects("Reword")
oEmbFile.Verb Verb:=xlPrimary
Set wd = oEmbFile.Object
With wd
'
'
'
'
End With
上面的代码可以在该位置进行编辑,对于当前目标而言似乎足够了。但是,对于使用全字窗口和功能区等打开,可以尝试
oEmbFile.Verb Verb:=xlVerbOpen