create a Field and assing a new value

M

Mauro Migliarini

Is there a way to create a new word Field and then SET a new value to it?
And how?

Thanks
 
G

Greg Maxey

Sub Scratchmacro()
ActiveDocument.Fields.Add Selection.Range, wdFieldQuote, Chr(34) & "New
Field Text" & Chr(34)
End Sub
 
M

Mauro Migliarini

Well.

Not like this.

I meant: create a new field, maybe called "Field1" and after that SET its
text value based on some code. Something like that:

if i = 1 Then
Field1 = "Text1"
Else
Field1 = "Text2"
End If


How can I do something like that?
Thanks
 
G

Greg Maxey

Sub ScratchMacro()
Dim i As Long
i = 3
Select Case i
Case Is < 3
ActiveDocument.FormFields("Text1").Result = "Some text here"
Case Is = 3
ActiveDocument.FormFields("Text1").Result = "Some other text here"
Case Else
ActiveDocument.FormFields("Text1").Result = "Still some other text here"
End Select
End Sub
 

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