Reference the name of a formfield bookmark in Word
I am filling in a form letter in Word using data from my excel worksheet. I
am using Formfields which I am new at. I know how to reference a specific bookmark name like: Dim appWD As Word.Application Set appWD = CreateObject("Word.Application.11") appWD.ActiveDocument.FormFields("Contact_Name").Se lect My question is, can I reference a bookmark name by a value in my worksheet. For example, something like: appWD.ActiveDocument.FormFields activecell.offset(1,2).value.select I keep getting an error. Would anyone know the exact syntax or method to do this? Thanks! |
Reference the name of a formfield bookmark in Word
"sharonm" schreef in bericht ... I am filling in a form letter in Word using data from my excel worksheet. I am using Formfields which I am new at. I know how to reference a specific bookmark name like: Dim appWD As Word.Application Set appWD = CreateObject("Word.Application.11") appWD.ActiveDocument.FormFields("Contact_Name").Se lect My question is, can I reference a bookmark name by a value in my worksheet. For example, something like: appWD.ActiveDocument.FormFields activecell.offset(1,2).value.select I keep getting an error. Would anyone know the exact syntax or method to do this? Thanks! Running Office 2000... Option Explicit 'I have a sample sheet with these cells: '- C3: Name '- C5: Address '- C7: Zipcode '- C9: City 'In a Word document (same path) I added '4 bookmarks: 'bmName, bmAddress, bmZipcode, bmCity 'References added in VB Editor: 'Microsoft Word 9.0 Object Library Public Sub xlsCells2wrdBookmarks() 'declare objects Dim wb As Workbook Dim ws As Worksheet Dim wrdApp As Word.Application Dim wrdDoc As Document 'assign object values Set wb = ThisWorkbook Set ws = wb.Sheets("Sheet1") Set wrdApp = CreateObject("Word.Application") Set wrdDoc = wrdApp.Documents.Open(wb.Path & "\" & "BOOKMARKS.doc") 'Run Word on the background wrdApp.Visible = False wrdDoc.Activate wrdApp.Selection.Goto wdGoToBookmark, , , "bmName" wrdApp.Selection.TypeText Text:=ws.Cells(3, 3).Value wrdApp.Selection.Goto wdGoToBookmark, , , "bmAddress" wrdApp.Selection.TypeText Text:=ws.Cells(5, 3).Value wrdApp.Selection.Goto wdGoToBookmark, , , "bmZipcode" wrdApp.Selection.TypeText Text:=ws.Cells(7, 3).Value wrdApp.Selection.Goto wdGoToBookmark, , , "bmCity" wrdApp.Selection.TypeText Text:=ws.Cells(9, 3).Value wrdDoc.Save wrdDoc.Close wrdApp.Quit 'clean up Set wrdDoc = Nothing Set wrdApp = Nothing Set ws = Nothing Set wb = Nothing End Sub |
All times are GMT +1. The time now is 03:35 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com