Solved

Changing Document Property Fields in Word with VBA

Posted on 2003-12-10
5
873 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
  • 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 30 total points
ID: 9926659
Exactly the same, except instead of

    .BuiltInDocumentProperties(wdPropertyLastAuthor)


you would say

    .CustomDocumentProperties(myCustomPropertyName)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now