Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADDING USER NAME TO DOCUMENT 4

Status
Not open for further replies.

FISKO

Technical User
Aug 30, 2005
113
GB
Hi is it possible to have a module in word, excell etc that grabs the username and places it on the bottom of the document when the user prints?
This would be very useful in school to find out who's wasting all the ink.
Thanks
 
Well it is certainly possible to grab the username and put it at the bottom of a document. You would have to rewrite the FilePrint command (in Word) and save that in normal.dot.

Gerry
 
Hi FISKO.
Alternatively, your printer may allow you to print an autmatic banner page before each print job listing the username.
 
Another alternative is to look at a printer management utility. These utilities allow total management of the printer including who prints what, when and from where (which machine).


Regards: tf1
 
Of course, you could just use the Insert|Field|Username approach ...

No vba or mucking around with printer/network management utilities is required, just a modification of the files and, preferably, the templates they're created from.

Cheers
 
macropod, that requires a manual insert. An manual action for each and every file. Even if the templates was altered, any existing file created from it will not automatically do an update. Unless of course that file already has that instruction. Yes any NEW documents created from the modified template(s) will work fine. I can not see how you can get the instruction to put the username in existing documents without either individual manual inserts, or VBA.

Gerry
 
You can force a print of all of the document properties by selecting Tools | Options | Print | and checking the Document Properties box.

I believe that the Author is the name entered on installation, but if you check the path in the Template section, it will show their login name to identify your ink-waster. (C:\Documents and Settings\"The_InkWaster"\Application Data\Microsoft\Templates\Normal.dot)

It sounds like you are in a lab with many computers, so this change may be required on every installation of Word.

Alas, the user could always uncheck that option if they found it.
 
Thanks Manata, this may go part way to a solution.
Still looking for a VB answer to grab the user name and add it to the header or footer.
 
mmm had a try with the Tools / Options / Print, however it prints on a seperate sheet and therefore wastes paper... Oh well on with the search, thanks any-hoo
 
Hi FISKO,

The following code can be used to ensure the username field is inserted (once) into every footer in the document.

Code:
Sub InsertUserName()
Dim oSection As Section
Dim oFoot As HeaderFooter
Dim oFld As Field
Dim UserField As Boolean
For Each oSection In ActiveDocument.Sections
    For Each oFoot In oSection.Footers
        If Not oFoot.LinkToPrevious Then
            With oFoot.Range
                UserField = False
                For Each oFld In .Fields
                    If oFld.Type = wdFieldUserName Then UserField = True
                Next
                If UserField = False Then
                    .Select
                    With Selection
                        If Trim(.Range.Text) <> "" Then
                            .Collapse (wdCollapseEnd)
                            .TypeText Chr(11)
                        End If
                        .Fields.Add Range:=Selection.Range, Type:=wdFieldUserName
                    End With
                End If
            End With
        End If
    Next
Next
End Sub

If you insert the code into the Normal.Dot template, and call it with both a Document_Open module and a Document_New module, that should be sufficient to ensure every document printed from Word shows the username in the footer.

Now all you've got to do is to change your users' Normal.Dot templates ...

Cheers
 
IMHO you shouldn't make changes like this to the normal template as it may have unforeseen side affects such as throwing labels out of alignment.

To do this successfully, I stick by my original recommendation: use a printer management utility.

Regards: tf1
 
macropod, that inserts the WORD username field. This is so easily modified that it is a joke to really consider it as any sort of identification.

Besides, using the Word username field does not seem quite fair, as it is simply the Author field. That means if Joe Blow authored the document, but Harry WhatHisName did the actual printing - it would be Joe Blow that had his name associated with the printing. That is not fair.

It would be far better to use the user system login name.

That being said, I also do not see the point, really, for all that code. Is it needed to deal with every single footer in every single section? The purpose is to identify whioever is printing. Once seems enough.
Code:
With Selection
 .EndKey Unit:=wdStory
 .Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = _
    .Sections(1).Footers(wdHeaderFooterPrimary) _
      .Range.Text & Environ("Username")
End With
would go to the end of the document and print the name of the person who is logged on.

I agree that modifying normal.dot has its down side, and from a technically clean (as far as Word is concerned) POV a printer utility is better.

Gerry
 
Hi Gerry,

The username and author are not necessarily one and the same, and Word has different fields for each.

As for putting the field in every footer, failing to do so means you only get the username if the last page is printed. Which I why my code inserts it in every footer.

The other problem I see with your approach is that it doesn't check to see whether the username is already there - it blindly goes ahead and inserts another copy anyway. The end result could be a document with a footer with multiple user names, or multiple instances of the same username.

Cheers
 
Thanks guys lots to look at and try here, I will let you know how it pans out.
 
Hi fumei, where does your code go?
 
Its ok I got it, both look good will try them out @ school on the network.
 
I have tried this but am having problems setting the users Normal.dot .I run a vanilla 2003 server network using folder redirection for the pupils work area, how do I set up the Normal.dot for them?
Any ideas, thanks
Semi stressed school tech
 
Hi Fisko,

Word creates a normal.dot file for each user automatically. So, all you need to do is to search for their normal.dot files and, presumably, replace them or add the code to them.

You'll probably find the users' normal.dot files lurking somewhere under:
C:\Documents and Settings\

Cheers
 
But note that if this is Word 2003, normal.dot is not created until the user makes a change to the default settings that requires a normal.dot (such as changing the default font). So if the users have not made any changes to the default settings, normal.dot will not exist.

Otherwise it will be located in documents and settings, username, applications data, microsoft, templates folder unless the install specified a different location.

Regards: tf1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top