Note that there are some explanatory texts on larger screens.

plurals
  1. POWord macro, storing the current selection (VBA)
    primarykey
    data
    text
    <p>I have a Word document that contains about 4000 form fields which I have to export afterwards to a database. The matter is that none of the 4000 fields have an information in the "Bookmark" field, thus I cannot get the information stored in them.</p> <p>I'm trying to create a macro to help the process of writing the bookmark (FormField.Name) but cannot manage to do it right. The matter is that I want to change the names of the FormFields contained in the user's selection, and only them. I've managed to come to this solution:</p> <pre><code>Sub Macro2() Dim myFile As String Dim fnum As Integer Dim sFileText As String Dim currentField As FormField myFile = "c:\testMacro.txt" fnum = FreeFile() Open myFile For Input As fnum For Each currentField In Selection.FormFields Input #fnum, sFileText With currentField .StatusText = sFileText .OwnStatus = True End With currentField.Select Application.WordBasic.FormFieldOptions Name:=sFileText Next currentField End Sub </code></pre> <p>But it doesn't work, because the Selection object is changed in the For Each loop and afterwards it only contains the first FormField of the selection.</p> <p>So here is my question, is there a way to save the current selection and load it back after having changed it.</p> <p>I've tried :</p> <pre><code>Dim mySelection as Selection Set mySelection = Selection </code></pre> <p>But if I change the Selection, the variable mySelection changes as well (which is quite normal...) and I didn't find any way to clone the object.</p> <p>Has someone an idea on how to do this?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload