Z
Zolo WordExpert
I've got a multicolumned form that's extremely complex.
Let's say the first column has 8 rows merged into a single
cell with lots of specific text - all bookmarked so as to
be programmatically accessible for automated modification
based on business rules. Column 2 displays all 8 rows,
every cell's content is a bookmark with preliminary text
that may or may not change. Column 3, 4 and 5 is a series
of 4 rows which actually has every other row merged. There
is a textinput formfield as the content of cells in column
3, and column 5 has a numeric-currency-formatted
formfield.
I am working on providing for the ability to dynamically
split the merged rows in columns 3,4, & 5. To begin, I
recorded a macro of doing one cell by hand - then I
optimized the generated code and put it into my
application. Now, when I run the code, I get a silly
cryptic useless 4198 error. The relevent code is pasted (I
know, it's a bit obtuse) below. Could someone give me an
idea of what is causing this error and what I can do to
workaround this issue - or if you know of a better method
to do something like this...
The Code:
' SplitCells Macro
' Two methods to go to needed cell containing
Formfield "txtLimitComp3"
Selection.GoTo What:=wdGoToBookmark,
Name:="txtLimitComp3"
' ActiveDocument.Bookmarks("txtLimitComp3").Range.Select
Selection.Copy
Selection.SelectCell
Selection.Cells.Split NumRows:=2, NumColumns:=1,
MergeBeforeSplit:=False
' Here we make it pretty setting all borders the same
With Selection.Cells
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
.Borders(wdBorderDiagonalDown).LineStyle =
wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle =
wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
Selection.MoveRight Unit:=wdCell
Selection.MoveDown Unit:=wdLine, Count:=1
' Now for the critical part - pasting the copied Formfield
Selection.Paste
' Make sure the entire field is part of the selection
Selection.MoveLeft Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
' Set all attributes of Formfield with new name
' Sometimes, this renames the previous Formfield -
is there a way
' to verify that the field being named is the right
one? a Refresh perhaps???
With Selection.FormFields(1)
.Name = "txtLimitRental1"
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = True
.HelpText = "Enter Policy Coverage Limits"
.OwnStatus = True
.StatusText = "Enter Policy Coverage Limits"
' ERROR 4198 Occurs on the following line EVERY TIME
' works fine doing this manually by hand
' if I leave out this line, then it seems the
Formfield doesn't
' get initialized and typed correctly
With .TextInput
.EditType Type:=wdRegularText, Default:="",
Format:=""
.Width = 25
End With
End With
' Now - I've found I have to go back to where I was and
rename the original
' back to what it was - this is ridiculous
Selection.MoveUp Unit:=wdLine, Count:=1
With Selection.FormFields(1)
.Name = "txtLimitComp3"
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = True
.HelpText = "Enter Policy Coverage Limits"
.OwnStatus = True
.StatusText = "Enter Policy Coverage Limits"
With .TextInput
' ERROR 4198 Occurs on the following line EVERY TIME
' works fine doing this manually by hand
' if I leave out this line, then it seems the
Formfield doesn't
' get initialized and typed correctly
.EditType Type:=wdRegularText, Default:="",
Format:=""
.Width = 25
End With
End With
'Got to next column, do it again (no formfield here)
Selection.MoveRight Unit:=wdCell
ActiveWindow.ActivePane.SmallScroll ToRight:=1
Selection.Copy
Selection.SelectCell
Selection.Cells.Split NumRows:=2, NumColumns:=1,
MergeBeforeSplit:=False
With Selection.Cells
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
.Borders(wdBorderDiagonalDown).LineStyle =
wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle =
wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
ActiveWindow.ActivePane.SmallScroll ToRight:=1
Selection.MoveRight Unit:=wdCell
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Paste
' And now, the final column
Selection.MoveRight Unit:=wdCell
Selection.Copy
Selection.SelectCell
Selection.Cells.Split NumRows:=2, NumColumns:=1,
MergeBeforeSplit:=False
With Selection.Cells
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleDouble
.LineWidth = wdLineWidth075pt
.Color = wdColorBlack
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
.Borders(wdBorderDiagonalDown).LineStyle =
wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle =
wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
Selection.MoveRight Unit:=wdCell
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Paste
Selection.MoveLeft Unit:=wdWord, Count:=1,
Extend:=wdExtend
' Tried to simply set the Bookmark name as below -
but this doesn't work
ActiveDocument.Bookmarks.Add Name:="numPremRental1",
Range:=Selection.Range
End Sub
Zolo - GGH (Guru getting Headache...)
Let's say the first column has 8 rows merged into a single
cell with lots of specific text - all bookmarked so as to
be programmatically accessible for automated modification
based on business rules. Column 2 displays all 8 rows,
every cell's content is a bookmark with preliminary text
that may or may not change. Column 3, 4 and 5 is a series
of 4 rows which actually has every other row merged. There
is a textinput formfield as the content of cells in column
3, and column 5 has a numeric-currency-formatted
formfield.
I am working on providing for the ability to dynamically
split the merged rows in columns 3,4, & 5. To begin, I
recorded a macro of doing one cell by hand - then I
optimized the generated code and put it into my
application. Now, when I run the code, I get a silly
cryptic useless 4198 error. The relevent code is pasted (I
know, it's a bit obtuse) below. Could someone give me an
idea of what is causing this error and what I can do to
workaround this issue - or if you know of a better method
to do something like this...
The Code:
' SplitCells Macro
' Two methods to go to needed cell containing
Formfield "txtLimitComp3"
Selection.GoTo What:=wdGoToBookmark,
Name:="txtLimitComp3"
' ActiveDocument.Bookmarks("txtLimitComp3").Range.Select
Selection.Copy
Selection.SelectCell
Selection.Cells.Split NumRows:=2, NumColumns:=1,
MergeBeforeSplit:=False
' Here we make it pretty setting all borders the same
With Selection.Cells
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
.Borders(wdBorderDiagonalDown).LineStyle =
wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle =
wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
Selection.MoveRight Unit:=wdCell
Selection.MoveDown Unit:=wdLine, Count:=1
' Now for the critical part - pasting the copied Formfield
Selection.Paste
' Make sure the entire field is part of the selection
Selection.MoveLeft Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
' Set all attributes of Formfield with new name
' Sometimes, this renames the previous Formfield -
is there a way
' to verify that the field being named is the right
one? a Refresh perhaps???
With Selection.FormFields(1)
.Name = "txtLimitRental1"
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = True
.HelpText = "Enter Policy Coverage Limits"
.OwnStatus = True
.StatusText = "Enter Policy Coverage Limits"
' ERROR 4198 Occurs on the following line EVERY TIME
' works fine doing this manually by hand
' if I leave out this line, then it seems the
Formfield doesn't
' get initialized and typed correctly
With .TextInput
.EditType Type:=wdRegularText, Default:="",
Format:=""
.Width = 25
End With
End With
' Now - I've found I have to go back to where I was and
rename the original
' back to what it was - this is ridiculous
Selection.MoveUp Unit:=wdLine, Count:=1
With Selection.FormFields(1)
.Name = "txtLimitComp3"
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = True
.HelpText = "Enter Policy Coverage Limits"
.OwnStatus = True
.StatusText = "Enter Policy Coverage Limits"
With .TextInput
' ERROR 4198 Occurs on the following line EVERY TIME
' works fine doing this manually by hand
' if I leave out this line, then it seems the
Formfield doesn't
' get initialized and typed correctly
.EditType Type:=wdRegularText, Default:="",
Format:=""
.Width = 25
End With
End With
'Got to next column, do it again (no formfield here)
Selection.MoveRight Unit:=wdCell
ActiveWindow.ActivePane.SmallScroll ToRight:=1
Selection.Copy
Selection.SelectCell
Selection.Cells.Split NumRows:=2, NumColumns:=1,
MergeBeforeSplit:=False
With Selection.Cells
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
.Borders(wdBorderDiagonalDown).LineStyle =
wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle =
wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
ActiveWindow.ActivePane.SmallScroll ToRight:=1
Selection.MoveRight Unit:=wdCell
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Paste
' And now, the final column
Selection.MoveRight Unit:=wdCell
Selection.Copy
Selection.SelectCell
Selection.Cells.Split NumRows:=2, NumColumns:=1,
MergeBeforeSplit:=False
With Selection.Cells
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleDouble
.LineWidth = wdLineWidth075pt
.Color = wdColorBlack
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorBlack
End With
.Borders(wdBorderDiagonalDown).LineStyle =
wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle =
wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
Selection.MoveRight Unit:=wdCell
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Paste
Selection.MoveLeft Unit:=wdWord, Count:=1,
Extend:=wdExtend
' Tried to simply set the Bookmark name as below -
but this doesn't work
ActiveDocument.Bookmarks.Add Name:="numPremRental1",
Range:=Selection.Range
End Sub
Zolo - GGH (Guru getting Headache...)