Loop through properties

G

Greg Maxey

I fear the answer is no, but hopefully someone knows a way or a better way
to achieve the goal.

I have a serialized numbered document (some file management system
requirement) that needs to have a company letterhead applied, company
letterhead styles applied, and mirror the page setup of the company
letterhead.

I know that I can pseudo copy PageSetup properties between documents like
this:

Sub Practice()
Dim oDoc1 As Word.Document
Dim oDOc2 As Word.Document
Set oDoc1 = Documents(1)
Set oDOc2 = Documents(2)
With oDoc1.PageSetup
.BottomMargin = oDOc2.PageSetup.BottomMargin
.LeftMargin = oDoc1.PageSetup.LeftMargin
'etc.
End With
End Sub

I was wondering if there is a way to loop through each of the PageSetup
properties rather than do it one property at a time? Or is there a way to
simply set the "complete" pagesetup of one document to = that of another
document?

Thanks.


--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the strong
man stumbles, or where the doer of deeds could have done them better. The
credit belongs to the man in the arena, whose face is marred by dust and
sweat and blood, who strives valiantly...who knows the great enthusiasms,
the great devotions, who spends himself in a worthy cause, who at the best
knows in the end the triumph of high achievement, and who at the worst, if
he fails, at least fails while daring greatly, so that his place shall never
be with those cold and timid souls who have never known neither victory nor
defeat." - TR
 
L

Lene Fredborg

Since page setup belongs to sections and since the last paragraph mark in a
one-section document includes section information, you could copy the last
paragraph mark from the source document to the target document. Something
like the following could be used as a starting point:

Sub CopyPageSetup()
Dim oDocSource As Document
Dim oDocTarget As Document

Set oDocSource = Documents("MySource.doc")
Set oDocTarget = Documents("MyTarget.doc")

oDocSource.Characters.Last.Copy
With oDocTarget
.Characters.Last.Select
Selection.Paste
End With

Set oDocSource = Nothing
Set oDocTarget = Nothing

End Sub

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
G

Greg Maxey

Lene,

Thanks. I will have to go back and check if the company template is a one
section affiair. This might just work.


Lene said:
Since page setup belongs to sections and since the last paragraph
mark in a one-section document includes section information, you
could copy the last paragraph mark from the source document to the
target document. Something like the following could be used as a
starting point:

Sub CopyPageSetup()
Dim oDocSource As Document
Dim oDocTarget As Document

Set oDocSource = Documents("MySource.doc")
Set oDocTarget = Documents("MyTarget.doc")

oDocSource.Characters.Last.Copy
With oDocTarget
.Characters.Last.Select
Selection.Paste
End With

Set oDocSource = Nothing
Set oDocTarget = Nothing

End Sub

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the
strong man stumbles, or where the doer of deeds could have done them
better. The credit belongs to the man in the arena, whose face is
marred by dust and sweat and blood, who strives valiantly...who knows
the great enthusiasms, the great devotions, who spends himself in a
worthy cause, who at the best knows in the end the triumph of high
achievement, and who at the worst, if he fails, at least fails while
daring greatly, so that his place shall never be with those cold and
timid souls who have never known neither victory nor defeat." - TR
 
M

Manfred F

Hi Greg,

to copy and paste page setup properties, there is a manual procedure that
works (w2003):
1) go to the source location, click "page setup" and then OK
2) go to the target location and repeat this or use ctrl-y to repeat
Maybe You can use this and do some experiments with the built-in word
dialogs and/or with sendkeys, if available (as I heard, this is not true for
W2007. But it should be possible to use Wordbasic.Sendkeys..)

Good luck

Manfred
 
G

Greg Maxey

Manfred,

Thanks. Will have a look and see if I can make something work.


--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the strong
man stumbles, or where the doer of deeds could have done them better. The
credit belongs to the man in the arena, whose face is marred by dust and
sweat and blood, who strives valiantly...who knows the great enthusiasms,
the great devotions, who spends himself in a worthy cause, who at the best
knows in the end the triumph of high achievement, and who at the worst, if
he fails, at least fails while daring greatly, so that his place shall never
be with those cold and timid souls who have never known neither victory nor
defeat." - TR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top