【发布时间】:2018-01-10 19:08:46
【问题描述】:
我正在尝试将 Word 书签从选定的 Word 文档中导入特定的 Excel 单元格。我有一个宏,它获取 excel 数据并将其填充到 Word 模板中。我还需要能够获取该 Word 文档并将其重新导入 Excel。这是我目前所拥有的:
Sub Import()
Dim wdDoc As Object
Dim wdFileName As Variant
Dim ws As Worksheet
Dim nextRow As Range
wdFileName = Application.GetOpenFilename("Word files,*.doc;*.docx", , _
"Browse for document") 'dialog box
If wdFileName = False Then
MsgBox "No File Selected."
Exit Sub
Else
Set wdDoc = CreateObject("Word.Application")
wdDoc.Visible = True
On Error Resume Next
wdDoc.Documents.Open Filename:=wdFileName
On Error GoTo 0
wdDoc.Documents(wdFileName).Activate
On Error GoTo 0
End If
With wdDoc 'start import
Set ws = ThisWorkbook.Sheets("Sheet1")
Set nextRow = Cells(Rows.Count, "B").End(xlUp).Offset(1)
ws.Range("H" & (nextRow.Row)).Value2 = wdDoc.Bookmarks("Bookmark1").Range.Value2
End With
wdDoc.Close SaveChanges:=False
End Sub
我在 "ws.Range("H" & (nextRow.Row)).Value2 = wdDoc.Bookmarks(" Named_Insured").Range.Value2"
我在这里俯瞰什么?
【问题讨论】:
标签: excel import ms-word bookmarks vba