floorfiller
12-15-2012, 01:05 AM
Hey guys,
I'm really new to VBA so please bare with me.
I'm working on a little project for work and I think I'm about halfway there. What I'm trying to accomplish is this:
I have a 2 column table and am generating additional rows in it. In the left most cell I just have basic text as a label, so I don't really care about increments for it.
however, in the right cell I am going to have a dollar amount that I would like to total using the form field calculation. In order to do this, I have to increment the bookmark and add that new bookmark to the calculation field. I think this is pretty easy to do, I just don't know the skills to make it happen.
here is a look at what i have so far:
Sub Macro1()
'
'add row at bottom of table
Selection.InsertRowsBelow 1
Selection.FormFields.add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.PreviousField.Select
With Selection.FormFields(1)
.Name = "label"
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
With .TextInput
.EditType Type:=wdRegularText, Default:="", Format:=""
.Width = 0
End With
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.PreviousField.Select
With Selection.FormFields(1)
.Name = "charge"
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
With .TextInput
.EditType Type:=wdNumberText, Default:="", Format:= _
"$#,##0.00;($#,##0.00)"
.Width = 0
End With
End With
End Sub
so the above works how i need it to, however i'm not sure of the syntax to increment the bookmark name with every new generation of a row. i assume i need to do some sort of static variable, but again i'm just not familiar enough to make it work.
any help is certainly appreciated :)
I'm really new to VBA so please bare with me.
I'm working on a little project for work and I think I'm about halfway there. What I'm trying to accomplish is this:
I have a 2 column table and am generating additional rows in it. In the left most cell I just have basic text as a label, so I don't really care about increments for it.
however, in the right cell I am going to have a dollar amount that I would like to total using the form field calculation. In order to do this, I have to increment the bookmark and add that new bookmark to the calculation field. I think this is pretty easy to do, I just don't know the skills to make it happen.
here is a look at what i have so far:
Sub Macro1()
'
'add row at bottom of table
Selection.InsertRowsBelow 1
Selection.FormFields.add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.PreviousField.Select
With Selection.FormFields(1)
.Name = "label"
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
With .TextInput
.EditType Type:=wdRegularText, Default:="", Format:=""
.Width = 0
End With
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.PreviousField.Select
With Selection.FormFields(1)
.Name = "charge"
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
With .TextInput
.EditType Type:=wdNumberText, Default:="", Format:= _
"$#,##0.00;($#,##0.00)"
.Width = 0
End With
End With
End Sub
so the above works how i need it to, however i'm not sure of the syntax to increment the bookmark name with every new generation of a row. i assume i need to do some sort of static variable, but again i'm just not familiar enough to make it work.
any help is certainly appreciated :)