Solved

Changing Document Property Fields in Word with VBA

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

    .BuiltInDocumentProperties(wdPropertyLastAuthor)


you would say

    .CustomDocumentProperties(myCustomPropertyName)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

691 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