J
John M
I've tried to write some code that doesn't work quite as I would like. Can
anyone help?
Various things are done correctly in the earlier part of the code, which I
don't need to bother you with. However I then want to add a new page to the
end and place a text box on there (left hand corner) with given text. This
is given below and works intermittently.
--------------
doc.Range(1).InsertBreak wdPageBreak
Selection.EndKey Unit:=wdStory
Set s = doc.Shapes.AddTextbox(msoTextOrientationHorizontal,
CentimetersToPoints(dcPageMarginLeft + dcPageWd / 2), _
CentimetersToPoints(dcPageMarginTop), dMaxWidth, dMaxHeight)
--------------
The VBA code exists in one document and applies to a new document DOC. It
seems to work the first time it is run but when the code is run a second
time it fails on the second line. The text selection doesn't move to the
last page, which causes the textbox to be incorrectly added to the "current"
page rather than the last.
I presume that the fact that the first DOC is still open means the SELECTION
applies to it rather than the second DOC.
Now I'm no expert in Word VBA having learned VBA with Excel (where I was
instructed not to use "Select" unless unavoidable). So it occurs to me that
there ought to be a way to Add a page and then put a text box on it without
using select.
Any suggestions?
anyone help?
Various things are done correctly in the earlier part of the code, which I
don't need to bother you with. However I then want to add a new page to the
end and place a text box on there (left hand corner) with given text. This
is given below and works intermittently.
--------------
doc.Range(1).InsertBreak wdPageBreak
Selection.EndKey Unit:=wdStory
Set s = doc.Shapes.AddTextbox(msoTextOrientationHorizontal,
CentimetersToPoints(dcPageMarginLeft + dcPageWd / 2), _
CentimetersToPoints(dcPageMarginTop), dMaxWidth, dMaxHeight)
--------------
The VBA code exists in one document and applies to a new document DOC. It
seems to work the first time it is run but when the code is run a second
time it fails on the second line. The text selection doesn't move to the
last page, which causes the textbox to be incorrectly added to the "current"
page rather than the last.
I presume that the fact that the first DOC is still open means the SELECTION
applies to it rather than the second DOC.
Now I'm no expert in Word VBA having learned VBA with Excel (where I was
instructed not to use "Select" unless unavoidable). So it occurs to me that
there ought to be a way to Add a page and then put a text box on it without
using select.
Any suggestions?