Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

Modifying built in document properties using an excel macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rakshit - 01 Nov 2006 11:54 GMT
I am having an interesting problem while trying to set the built in
document properties of a word file using an excel macro. I am picking
the values from an excel sheet and trying to set the values for each
.doc file in a folder one by one. The following code runs perfect the
first time and sets the new values for all built in properties for all
the word files in the "C:\Test" folder.
But when i run the code a second time with new values, it executes
without any error but doesn't set the new values (the doc files have
the old values itself).
Can someone help please? Urgent....

Sub Macro2()

Dim i As Integer

Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Set wordApp = CreateObject("Word.Application")

With Application.FileSearch
.NewSearch
.LookIn = "C:\Test"
.SearchSubFolders = False
.Filename = "*.doc"
.Execute

For i = 1 To .FoundFiles.count

ThisFile1 = Range("B" & i + 1).Value
ThisFile2 = Range("C" & i + 1).Value
ThisFile3 = Range("D" & i + 1).Value

Set wordDoc = wordApp.Documents.Open(Filename:=.FoundFiles(i))

wordApp.ActiveDocument.BuiltinDocumentProperties("Title") = ThisFile2
wordApp.ActiveDocument.BuiltinDocumentProperties("Subject") = ThisFile3
wordApp.ActiveDocument.BuiltinDocumentProperties("Author") = ThisFile4

wordDoc.Save
wordDoc.Close

Next i
End With

End Sub
Lüko Willms - 01 Nov 2006 13:15 GMT
Am Wed, 1 Nov 2006 10:54:17 UTC,  schrieb "Rakshit"
<raksh15@gmail.com>  auf microsoft.public.word.vba.general :

> wordApp.ActiveDocument.BuiltinDocumentProperties("Title") = ThisFile2

 try to modify not the object as such, but its "Value" property, like
this:

wordApp.ActiveDocument.BuiltinDocumentProperties("Title").Value =
ThisFile2

just hoping that "ThisFile2" is a text string...

Yours,
L.W.
Rakshit - 03 Nov 2006 07:40 GMT
Hi Luko,
Thanks so much for the help. It really helped. I tried working around
with what you suggested and stumbled upon the solution to the problem.
I had to basically add a line before saving and closing the files like
the following.

wordApp.ActiveDocument.Saved = False
wordDoc.Save
wordDoc.Close

this saves the files each time it opens it new by making it's saved
property false.
Thanks again for the help.

Yours,
Rakshit
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.