我正在嘗試使用 ms Access 打開 ms word,創建表單域和表格,但最終總是空的。我嘗試使用相同的代碼,但將“with doc”之間的整個代碼替換為 .formfields("TxtDate").result = me.txt2 并且能夠將我在 txt2 中輸入的任何內容傳輸到位于 ms word 中的表單欄位中。因此,我不確定代碼的哪一部分出錯了。想就我的代碼尋求幫助。謝謝
Function FillWordForm()
Dim appword as Word.Application
Dim doc as Word.Document
Dim Path as String
On Error Resume Next
Error.Clear
Path = "H:\project delta\test.docx"
Set appword = GetObject(, "word.application")
If Err.Number <> 0 then
Set appword = New Word.Application
appword.Visible = true
End if
Set doc = appword.Documents.open(Path, , False)
With Doc
Selection.TypeParagraph
Selection.FormFields.Add Range:=Selection.Range, Type:= _
WdFieldFormTextInput
ActiveDocument.FormFields.Shaded = Not ActiveDocument.FormFields.Shaded
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=13, NumColumns:= _
4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = True
.Cell(1,1).Select
Selection.TypeText Text:="S/N"
.Cell(1,2).Select
Selection.TypeText Text:="Package Title"
.Cell(1,3).Select
Selection.TypeText Text:="Reference"
.Cell(1,4).Select
Selection.TypeText Text:="Month"
End With
appword.Visible = True
appword.Activate
End With
Set doc = Nothing
Set appword = Nothing
End Function
uj5u.com熱心網友回復:
考慮到評論,問題可能是由于 Word 行程仍在后臺運行,即使任務管理器中沒有顯示。這可能是由對 Word 物件的不合格參考引起的。
每個和用法和代碼appword.前面的前綴應該每次都運行。現在對我有用。SelectionActiveDocument
這也可能發生在其他 Office 應用程式(Excel、Outlook、PowerPoint 等)的自動化代碼中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/429078.html
