W
Wayne Herbert
I want to insert two styleref fields, separted by a hyphen,into a
header so that I can get a dictionary like heading for the first and
last entries on a page.
What I want to get is FIRSTWORD-LASTWORD. What I am instead getting
when I automate the process is -LASTWORDFIRSTWORD. I am clearly
missing something (quite new to this), and I don't know what.
First, I recorded a macro in Word which set up what I wanted:
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"STYLEREF FirstThree ", PreserveFormatting:=True
Selection.TypeText Text:="-"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"STYLEREF FirstThree \l ", PreserveFormatting:=True
The fields looked good on my sample, hand created document. Next I
translated this into Delphi Object Pascal calls as follows.
// select the page header
Word.ActiveWindow.ActivePane.View.SeekView :=
wdSeekCurrentPageHeader;
// write out the first styleref field
OleVar := wdFieldEmpty;
OleVar2 := WideString('STYLEREF FirstThree ');
OleVar3 := true;
Word.Selection.Fields.Add(Word.Selection.Range, OleVar, OleVar2,
OleVar3);
// write out the hyphen
Word.Selection.TypeText(WideString('-'));
// write out the second styleref field
OleVar2 := WideString('STYLEREF FirstThree \l ');
Word.Selection.Fields.Add(Word.Selection.Range, OleVar, OleVar2,
OleVar3);
However, when I execute this code, I get jumbled output.
Once I do get this straightened out, I would like to be able to select
the whole thing so that I can apply a font and bolding to the styleref
fields and the hyphen.
Pointers in the right direction would be appreciated.
header so that I can get a dictionary like heading for the first and
last entries on a page.
What I want to get is FIRSTWORD-LASTWORD. What I am instead getting
when I automate the process is -LASTWORDFIRSTWORD. I am clearly
missing something (quite new to this), and I don't know what.
First, I recorded a macro in Word which set up what I wanted:
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"STYLEREF FirstThree ", PreserveFormatting:=True
Selection.TypeText Text:="-"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"STYLEREF FirstThree \l ", PreserveFormatting:=True
The fields looked good on my sample, hand created document. Next I
translated this into Delphi Object Pascal calls as follows.
// select the page header
Word.ActiveWindow.ActivePane.View.SeekView :=
wdSeekCurrentPageHeader;
// write out the first styleref field
OleVar := wdFieldEmpty;
OleVar2 := WideString('STYLEREF FirstThree ');
OleVar3 := true;
Word.Selection.Fields.Add(Word.Selection.Range, OleVar, OleVar2,
OleVar3);
// write out the hyphen
Word.Selection.TypeText(WideString('-'));
// write out the second styleref field
OleVar2 := WideString('STYLEREF FirstThree \l ');
Word.Selection.Fields.Add(Word.Selection.Range, OleVar, OleVar2,
OleVar3);
However, when I execute this code, I get jumbled output.
Once I do get this straightened out, I would like to be able to select
the whole thing so that I can apply a font and bolding to the styleref
fields and the hyphen.
Pointers in the right direction would be appreciated.