PDA

View Full Version : How to insert name of author to footer with helping VBA?



akokin
08-19-2007, 06:00 AM
Hello. I tried to insert in footer the author name of the document (menu View | Header and Footer). And then I insert autotext. But I had inserting only field {Authors}. And I would like get the real name of author this document (Service | Options | tab User) but not field.
How can I insert it with helping VBA?
Thank you.

mdmackillop
08-19-2007, 07:19 AM
Hi Akokin,
Welcome to VBAX

Sub AddUserToFooter()
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text _
= Environ("Username")
End Sub

akokin
08-19-2007, 07:39 AM
thank you very much! It's working. It insert name of my computer but not author of this document. Why?
I made this macro:

sub footherInsert ()
ActiveDocument.ActiveWindow.View.SeekView = wdSeekCurrentPageFooter
NormalTemplate.AutoTextEntries("Автор, стр. <№>, дата").Insert _
Where:=Selection.Range
ActiveWindow.View.ShowFieldCodes = False
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
end sub

Unfortunaly, I don't all understand in this code. Nevertheless I'm learning.

mdmackillop
08-19-2007, 07:50 AM
What version of Word are you running? I don't see Service in my version. Are you wanting Author from the Documents Properties?

akokin
08-19-2007, 07:56 AM
Word 2003 Russian. maybe this reason. Sorry, not Service but Tools. Yes, from the Documents Properties.

mdmackillop
08-19-2007, 08:06 AM
This should get Author from Properties.
Sub AddAuthorToFooter()
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text _
= ActiveDocument.BuiltInDocumentProperties("Author")
End Sub

akokin
08-19-2007, 08:37 AM
Yes. Heartfelt gratitude!