?
Solved

Changing Document Property Fields in Word with VBA

Posted on 2003-12-10
5
Medium Priority
?
920 Views
Last Modified: 2007-12-19
I have created a number of property fields in the document properties area in a word document.  I want to be able to change the information in each of those fields in a macro.  What is the best way to do this?

Also, on a side note, is there anyway to retrieve information from an exchange server from word.  What I am trying to do, is use the information in exchange to populate the document with the current users details.
0
Comment
Question by:fulama
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:calebS
ID: 9918516
Not sure about the side note, however below is a quick bit of code to change the properties.

' My quick bit of code
With ActiveDocument
    .BuiltInDocumentProperties(wdPropertyTitle) = "My document"
    .BuiltInDocumentProperties(wdPropertySubject) = "Creating a new Macro"
End With

Note, I am assuming you know how to create a macro etc. If you don't, please ask and I will assist.


Also see below a list of other properties.

    .BuiltInDocumentProperties(wdPropertyLastAuthor)
    .BuiltInDocumentProperties(wdPropertyKeywords)
    .BuiltInDocumentProperties(wdPropertyComments)
    .Name
    .Path
    .BuiltInDocumentProperties(wdPropertyTemplate)
    .BuiltInDocumentProperties(wdPropertyTimeCreated)
    .BuiltInDocumentProperties(wdPropertyTimeLastSaved)
    .BuiltInDocumentProperties(wdPropertyLastAuthor)
    .BuiltInDocumentProperties(wdPropertyRevision)
    .BuiltInDocumentProperties(wdPropertyVBATotalEdit)
    .BuiltInDocumentProperties(wdPropertyTimeLastPrinted)
    .BuiltInDocumentProperties(wdPropertyPages)
    .BuiltInDocumentProperties(wdPropertyWords)
    .BuiltInDocumentProperties(wdPropertyCharacters)
    .BuiltInDocumentProperties(wdPropertyParas)
    .BuiltInDocumentProperties(wdPropertyLines)
    .BuiltInDocumentProperties(wdPropertyBytes)
0
 
LVL 9

Expert Comment

by:gilbar
ID: 9920375
if you're on winNT or 2000 or XP, this will make and open a .txt file with user-name's info:
Sub userInfo()
   Dim objWSH
   Dim useName As String
   Dim outFil As String
   useName = "user-Name"
   outFil = "c:\outputFile.txt"
   Set objWSH = CreateObject("WScript.Shell")
   Call objWSH.Run("cmd /c echo y| net user " & useName & " /domain > " & outFil, 0, True)
   Set objWSH = Nothing
   Documents.Open FileName:=outFil
End Sub
0
 
LVL 9

Expert Comment

by:gilbar
ID: 9920412
the windows command 'net user user-name /domain' what gets the info.
IMPORTANT NOTE. . .  in this case, '/domain' is literal, not something to change to your domain name.  it is a switch that tells command to look at your domain, not just your computer, so it has to be typed in as '/domain', not '/microsoft.com' or such
0
 

Author Comment

by:fulama
ID: 9924430
Thanks calebS and gilbar

calebS - Do you know how to reference custom made properties in word?  The code you gave me works for the standard properties, but not for ones that I have made.

gilbar - The code you gave me access the NT user information.  I require access to the Mail (exchange) server to access the Global Address Listing for the current user and to be able to grab things like email address, phone number etc from there and put that in word.
0
 
LVL 1

Accepted Solution

by:
calebS earned 120 total points
ID: 9926659
Exactly the same, except instead of

    .BuiltInDocumentProperties(wdPropertyLastAuthor)


you would say

    .CustomDocumentProperties(myCustomPropertyName)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question