S
salavine1
Hello,
I have a word document with at table that has 5 columns and anywhere
from 0 to 999 rows. Each table cell will have a textbox in it. I need
to change all the textbox names to a standard format as well as
incremental. If a row is deleted in the middle, I need to rename all
the textboxes after the deletion. The creating of this table and
textbox is automated and I don’t have the ability to change that. I
have to format after the fact.
The automated naming is as follows. Where # represents the number.
1st row: SqdMetContNo, SqdLabEquipDesc, SqdDatesUsed, SqdLastCal,
SqdDueDate
2nd – 9th rows: SqdMetContNo__#, SqdLabEquipDesc__#, SqdDatesUsed__#,
SqdLastCal__#, SqdDueDate__#
10th-99th rows: SqdMetContNo_##, SqdLabEquipDesc_##, SqdDatesUsed_##,
SqdLastCal_##, SqdDueDate_##
100 – 999 rows: SqdMetContNo###, SqdLabEquipDesc###, SqdDatesUsed###,
SqdLastCal###, SqdDueDate###
Here is the code I was using and thought that it was working until I
did further testing and found that it didn’t. Any help would be
appreciated.
Private Sub CheckTextBoxNames()
On Error Resume Next
Dim f As Object
Dim tb As TextBox
Dim iRowCounter As Integer
Dim sFieldName As String
iRowCounter = 0
sFieldName = ""
‘ Loops through the all the textbox objects.
For Each f In ActiveDocument.Fields
If f.OLEFormat.ClassType = "Forms.TextBox.1" Then
Set tb = f.OLEFormat.Object
‘ Returns only the left part of the name.
sFieldName = Len(tb.Name) - 3)
' Checks the name to see if it is the first or
after that.
Select Case sFieldName
Case Is = "SqdMetCon"
tb.Name = RenameTextBoxNames
("SqdMetContNo", iRowCounter)
Case Is = "SqdLabEquipD"
tb.Name = RenameTextBoxNames
("SqdLabEquipDesc", iRowCounter)
Case Is = "SqdDatesU"
tb.Name = RenameTextBoxNames
("SqdDatesUsed", iRowCounter)
Case Is = "SqdLast"
tb.Name = RenameTextBoxNames("SqdLastCal",
iRowCounter)
Case Is = "SqdDueD"
tb.Name = RenameTextBoxNames("SqdDueDate",
iRowCounter)
iRowCounter = iRowCounter + 1
Case Is = "SqdMetContNo"
tb.Name = RenameTextBoxNames
("SqdMetContNo", iRowCounter)
Case Is = "SqdLabEquipDesc"
tb.Name = RenameTextBoxNames
("SqdLabEquipDesc", iRowCounter)
Case Is = "SqdDatesUsed"
tb.Name = RenameTextBoxNames
("SqdDatesUsed", iRowCounter)
Case Is = "SqdLastCal"
tb.Name = RenameTextBoxNames("SqdLastCal",
iRowCounter)
Case Is = "SqdDueDate"
tb.Name = RenameTextBoxNames("SqdDueDate",
iRowCounter)
iRowCounter = iRowCounter + 1
End Select
End If
Next f
End Sub
Private Function RenameTextBoxNames(sFieldName As String, iRowCounter
As Integer)
On Error Resume Next
Dim sNewName As String
sNewName = ""
If iRowCounter <= 9 Then
sNewName = sFieldName & "__" & iRowCounter
ElseIf (iRowCounter > 9) And (iRowCounter < 100) Then
sNewName = sFieldName & "_" & iRowCounter
ElseIf iRowCounter >= 100 Then
sNewName = sFieldName & iRowCounter
End If
RenameTextBoxNames = sNewName
End Function
I have a word document with at table that has 5 columns and anywhere
from 0 to 999 rows. Each table cell will have a textbox in it. I need
to change all the textbox names to a standard format as well as
incremental. If a row is deleted in the middle, I need to rename all
the textboxes after the deletion. The creating of this table and
textbox is automated and I don’t have the ability to change that. I
have to format after the fact.
The automated naming is as follows. Where # represents the number.
1st row: SqdMetContNo, SqdLabEquipDesc, SqdDatesUsed, SqdLastCal,
SqdDueDate
2nd – 9th rows: SqdMetContNo__#, SqdLabEquipDesc__#, SqdDatesUsed__#,
SqdLastCal__#, SqdDueDate__#
10th-99th rows: SqdMetContNo_##, SqdLabEquipDesc_##, SqdDatesUsed_##,
SqdLastCal_##, SqdDueDate_##
100 – 999 rows: SqdMetContNo###, SqdLabEquipDesc###, SqdDatesUsed###,
SqdLastCal###, SqdDueDate###
Here is the code I was using and thought that it was working until I
did further testing and found that it didn’t. Any help would be
appreciated.
Private Sub CheckTextBoxNames()
On Error Resume Next
Dim f As Object
Dim tb As TextBox
Dim iRowCounter As Integer
Dim sFieldName As String
iRowCounter = 0
sFieldName = ""
‘ Loops through the all the textbox objects.
For Each f In ActiveDocument.Fields
If f.OLEFormat.ClassType = "Forms.TextBox.1" Then
Set tb = f.OLEFormat.Object
‘ Returns only the left part of the name.
sFieldName = Len(tb.Name) - 3)
' Checks the name to see if it is the first or
after that.
Select Case sFieldName
Case Is = "SqdMetCon"
tb.Name = RenameTextBoxNames
("SqdMetContNo", iRowCounter)
Case Is = "SqdLabEquipD"
tb.Name = RenameTextBoxNames
("SqdLabEquipDesc", iRowCounter)
Case Is = "SqdDatesU"
tb.Name = RenameTextBoxNames
("SqdDatesUsed", iRowCounter)
Case Is = "SqdLast"
tb.Name = RenameTextBoxNames("SqdLastCal",
iRowCounter)
Case Is = "SqdDueD"
tb.Name = RenameTextBoxNames("SqdDueDate",
iRowCounter)
iRowCounter = iRowCounter + 1
Case Is = "SqdMetContNo"
tb.Name = RenameTextBoxNames
("SqdMetContNo", iRowCounter)
Case Is = "SqdLabEquipDesc"
tb.Name = RenameTextBoxNames
("SqdLabEquipDesc", iRowCounter)
Case Is = "SqdDatesUsed"
tb.Name = RenameTextBoxNames
("SqdDatesUsed", iRowCounter)
Case Is = "SqdLastCal"
tb.Name = RenameTextBoxNames("SqdLastCal",
iRowCounter)
Case Is = "SqdDueDate"
tb.Name = RenameTextBoxNames("SqdDueDate",
iRowCounter)
iRowCounter = iRowCounter + 1
End Select
End If
Next f
End Sub
Private Function RenameTextBoxNames(sFieldName As String, iRowCounter
As Integer)
On Error Resume Next
Dim sNewName As String
sNewName = ""
If iRowCounter <= 9 Then
sNewName = sFieldName & "__" & iRowCounter
ElseIf (iRowCounter > 9) And (iRowCounter < 100) Then
sNewName = sFieldName & "_" & iRowCounter
ElseIf iRowCounter >= 100 Then
sNewName = sFieldName & iRowCounter
End If
RenameTextBoxNames = sNewName
End Function