Missing bookmarks

L

LEU

I have hundreds of old documents that were created with am old template that
has missing bookmarks. There are 2 TextForm form fields, 2 Drop-Down form
fields and 2 CheckBox form fields. I have created a new template with
userforms. When I open an old document in our network, I save it to my C
drive. Then in a new document I open my userform and run this macro (Created
with help from Greg Maxey):

Private Sub CmdPaste1_Click()
Dim DocA As Document
Dim oFF As FormFields
Set DocA = Documents.Open("c:\Temp.doc")
Set oFF = ActiveDocument.FormFields
Me.Text3.Value = oFF("Text55").Result
Me.cm1.Value = oFF("DropDown1").Result
‘and so on
DocA.Close
Kill "c:\Temp.doc"
Set DocA = Nothing
Set oFF = Nothing
End Sub

Is there a way to give the missing TextForm, Drop-Down and CheckBox form
fields a temporary bookmark so I can copy them into my userform?
 
G

Greg Maxey

I have hundreds of old documents that were created with am old template that
has missing bookmarks. There are 2 TextForm form fields, 2 Drop-Down form
fields and 2 CheckBox form fields. I have created a new template with
userforms. When I open an old document in our network, I save it to my C
drive. Then in a new document I open my userform and run this macro (Created
with help from Greg Maxey):

Private Sub CmdPaste1_Click()
Dim DocA As Document
Dim oFF As FormFields
Set DocA = Documents.Open("c:\Temp.doc")
Set oFF = ActiveDocument.FormFields
Me.Text3.Value = oFF("Text55").Result
Me.cm1.Value = oFF("DropDown1").Result
'and so on
DocA.Close
Kill "c:\Temp.doc"
Set DocA = Nothing
Set oFF = Nothing
End Sub

Is there a way to give the missing TextForm, Drop-Down and CheckBox form
fields a temporary bookmark so I can copy them into my userform?

LEU,

See:

http://gregmaxey.mvps.org/Rename_Formfields_Globally.htm

After running the macro in that link your fields should be renamed/
bookmarked with the default names.

If all of your documents have the same layout, you might be able to
use the formfield index number in place of the name. For example. The
first formfield will be oFF(1).
 
L

LEU

Greg,

When I plug in your macro and run it I loose all the existing data in the
fields. How do I keep this from happening?

LEU
 
G

Greg Maxey

Dooohh!!! ;-)

Try:

Sub GlobalRenameFormFields()
Dim oFrmFlds As FormFields
Dim pIndex As Long
Dim i As Long
Dim j As Long
Dim k As Long
pIndex = 0
i = 0
j = 0
k = 0
On Error Resume Next
ActiveDocument.Unprotect
On Error GoTo 0
Set oFrmFlds = ActiveDocument.FormFields
For pIndex = 1 To oFrmFlds.Count
Dim oStr As String
Dim oCheck As Boolean
Dim oDD As Long
oFrmFlds(pIndex).Select
Select Case oFrmFlds(pIndex).Type
Case wdFieldFormTextInput
oStr = oFrmFlds(pIndex).Result
i = i + 1
With Dialogs(wdDialogFormFieldOptions)
.Name = "Text" & i
.Execute
End With
oFrmFlds(pIndex).Result = oStr
Case wdFieldFormCheckBox
oCheck = oFrmFlds(pIndex).CheckBox.Value
j = j + 1
With Dialogs(wdDialogFormFieldOptions)
.Name = "Check" & j
.Execute
End With
oFrmFlds(pIndex).CheckBox.Value = oCheck
Case wdFieldFormDropDown
oDD = oFrmFlds(pIndex).DropDown.Value
k = k + 1
With Dialogs(wdDialogFormFieldOptions)
.Name = "DropDown" & k
.Execute
End With
oFrmFlds(pIndex).DropDown.Value = oDD
Case Else
'Do Nothing
End Select
Next pIndex
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
 
G

Greg Maxey

You are going to have to give me more to work with. Open one of your
documents and step through the macro one line at a time using the F8 key.
What line generates the error? What is the string?

If the string is the text of one of your unnamed/unbookmarked formfields,
then you may have to use the index method.
 
L

LEU

It's at the following spot in the macro:

oFrmFlds(pIndex).Result = oStr

The error happens in textform field ('Text27') that has a lot of text in it.
 
L

LEU

It's the same 6 fields in every document that are not named. Is there a way
to just name those 6?
 
G

Greg Maxey

As I said earlier:

If all of your documents have the same layout, you might be able to
use the formfield index number in place of the name. For example. The
first formfield will be oFF(1).

So instead of something like:

Me.Text3.Value = oFF("Text55").Result

You might be able to use something like:

Me.Text3.Value = oFF(X).Result

Where "X" is the index number of the field.
 
G

Greg Maxey

Well if you have the formfield of interest selected, you could count the
formfields from the beginning of the document to the end of the selected
range. That should give you the index number.

Sub Test()
Dim oDoc As Document
Set oDoc = ActiveDocument
MsgBox oDoc.Range(0, Selection.Range.End).FormFields.Count

End Sub
 
G

Greg Maxey

Good. Sometimes asking questions helps me find my own answers too. What
did you finally end up using?
 
L

LEU

Hi Greg,

I printed out a blank document and just counted the formfields from the
beginning of the document to the end and put a number next to each formfield.
Then I just plugged in the number where I needed to.

Again thank you for all your help.

LEU
 
G

Greg Maxey

Hi Greg,

I printed out a blank document and just counted the formfields from the
beginning of the document to the end and put a number next to each formfield.
Then I just plugged in the number where I needed to.

Again thank you for all your help.

LEU









- Show quoted text -

That works! Glad I could help.
 
D

Doug Robbins - Word MVP

Why the bottom post? You a submariner or something? <G,D&R>

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Greg Maxey

Doug,

It's that horrendous new "Google Groups" interface. When I use it (at work)
the posts appear at the bottom. If I can change that, I have figured out
how.

Nice shot just the same ;-).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top