O
Omatase
I'm moving some text around manually in a word doc using some c# (I
couldn't find a word.csharp newsgroup, please respond in vba if it
makes you feel more comfortable though).
Moving characters around a word document one character at a time is
extremely slow. Even if the document isn't visible. Can someone offer
a suggestion to speeding the below code up? I'm thinking about some
sort of way to tell Word to not process events (or something like
that) while I'm moving everything one character at a time.
Range cellRange = aDoc.Tables.Item(1).Cell(1, 1).Range;
object collapseDirection = WdCollapseDirection.wdCollapseStart;
for (int i = mergeFields.Characters.Count; i > 0; i--)
{
string character = mergeFields.Characters.Item(i).Text;
if (mergeFields.Characters.ShapeRange.Shapes.Count == 0)
{
// add this character directly to our range
object fieldText = character;
// add our field
object type = WdFieldType.wdFieldEmpty;
cellRange.Collapse(ref collapseDirection);
cellRange.Text += character;
// remove this character from its original position
object unit = WdUnits.wdCharacter;
object count = 1;
mergeFields.Characters.Item(i).Delete(ref unit, ref count);
}
}
Any help is appreciated
Thanks
couldn't find a word.csharp newsgroup, please respond in vba if it
makes you feel more comfortable though).
Moving characters around a word document one character at a time is
extremely slow. Even if the document isn't visible. Can someone offer
a suggestion to speeding the below code up? I'm thinking about some
sort of way to tell Word to not process events (or something like
that) while I'm moving everything one character at a time.
Range cellRange = aDoc.Tables.Item(1).Cell(1, 1).Range;
object collapseDirection = WdCollapseDirection.wdCollapseStart;
for (int i = mergeFields.Characters.Count; i > 0; i--)
{
string character = mergeFields.Characters.Item(i).Text;
if (mergeFields.Characters.ShapeRange.Shapes.Count == 0)
{
// add this character directly to our range
object fieldText = character;
// add our field
object type = WdFieldType.wdFieldEmpty;
cellRange.Collapse(ref collapseDirection);
cellRange.Text += character;
// remove this character from its original position
object unit = WdUnits.wdCharacter;
object count = 1;
mergeFields.Characters.Item(i).Delete(ref unit, ref count);
}
}
Any help is appreciated
Thanks