我使用.FormFields("WordBookmarkName").Result = stringFromAccess
方法將數據從MS-Access傳遞到MS-Word文檔。將MS-Access string> 255個字符傳遞到MS-Word字段
看來它只能傳遞255個字符。有什麼方法可以在MS-Word中傳遞給我的領域?
編輯:
這是代碼的簡化版本,我使用的作品確定爲255個字符:
Dim startForms As String
Dim appWord As Word.Application
Dim doc As Word.Document
startForms = String(256, "x")
Set appWord = GetObject(, "Word.Application") 'Set appWord object variable to running instance of Word.
If Err.Number <> 0 Then
Set appWord = New Word.Application 'If Word isn't open, create a new instance of Word.
End If
Set doc = appWord.Documents.Open("C:\myFolder\MyForm.docx", , True)
With doc
.FormFields("wdStartForms").Result = "" 'Clear anything currently in the form's field
.FormFields("wdStartForms").Result = startForms
.Visible = True
.Activate
End With
Set doc = Nothing
Set appWord = Nothing
JohnnyBones:這是我經過改編的代碼你的答案;使用ActiveDocument
是行不通的,所以我繼續使用doc
參考我就做,它似乎後,與256+字符來確定:
Dim startForms As String
Dim appWord As Word.Application
Dim doc As Word.Document
startForms = String(256, "x")
Set appWord = GetObject(, "Word.Application") 'Set appWord object variable to running instance of Word.
If Err.Number <> 0 Then
Set appWord = New Word.Application 'If Word isn't open, create a new instance of Word.
End If
Set doc = appWord.Documents.Open("C:\myFolder\MyForm.docx", , True)
With doc
.FormFields("wdStartForms").Result = "" 'Clear anything currently in the form's field
.Bookmarks("wdStartForms").Range.Fields(1).Result.Text = startForms
.Visible = True
.Activate
End With
Set doc = Nothing
Set appWord = Nothing
索引通常爲1:通過FormFields,名稱/書籤通常「覆蓋」FormField,而不是其他任何東西。因此它的範圍「覆蓋」1個字段,索引是範圍中的「第n個」字段,而不是整個文檔。從理論上講,書籤可以被移動(但是可以在表單中創建一個「錯誤狀態」),理論上AFAICR可以將字段嵌套在FormField中,這可能會改變索引。但我幾乎沒有見過它。 – 2014-11-24 10:54:02
ahh ok,很高興知道:)'.Fields(1)'當我的字段有255個字符時填充,但不填充256個字符。我一直在測試'String(255,「x」)'字符串(256,「x」)'。 – 2014-11-24 11:23:49
實際上,它沒有填充,我剛剛評論了錯誤位 – 2014-11-24 11:40:10