BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Accessing WORD field from Delphi

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Marinus Willemstijn
Guest





PostPosted: Wed Mar 28, 2007 8:12 am    Post subject: Accessing WORD field from Delphi Reply with quote



I have a Delphi application which has the functionality to upload and store
Word files to a database. Currently the user uploading the file manually
types in the version nr of the Word file (contained in the footer of the
document as normal text) into the database when uploading.

I now want to change the application to read the version nr from the file
being uploaded. I have done a lot of reading on this and everytime it gets
back to Bookmarks and Fields. Somehow I am not grasping how I can do this. I
can find a specific Bookmark in the Word Document but still could not figure
out how to create some sort of field where the user can type in the Version
Nr (Or it be automatically updated) by Word and then when uploading it to
the application, the app "reads" that field value to populate the Version Nr
Field of the database. I used RevNum Field type in Word but cannot access
the value of RevNum.

I used the following code:

if WordApp.ActiveDocument.Bookmarks.Exists('VERSIONNR') then
showmessage('Found - Version Nr:
'+WordApp.ActiveDocument.FormFields.Item('VERSIONNR').Result)
else
showmessage('Not Found');

I hope my explanation is sufficient to guide someone to assist me in this
matter.

Thank you in advance!
Marinus
Back to top
Dex
Guest





PostPosted: Wed Apr 11, 2007 12:40 am    Post subject: Re: Accessing WORD field from Delphi Reply with quote



Marinus Willemstijn wrote: >>>

I have a Delphi application which has the functionality to upload and
store Word files to a database. Currently the user uploading the file
manually types in the version nr of the Word file (contained in the
footer of the document as normal text) into the database when
uploading.

I now want to change the application to read the version nr from the
file being uploaded. I have done a lot of reading on this and
everytime it gets back to Bookmarks and Fields. Somehow I am not
grasping how I can do this. I can find a specific Bookmark in the
Word Document but still could not figure out how to create some sort
of field where the user can type in the Version Nr (Or it be
automatically updated) by Word and then when uploading it to the
application, the app "reads" that field value to populate the Version
Nr Field of the database. I used RevNum Field type in Word but cannot
access the value of RevNum.

I used the following code:

if WordApp.ActiveDocument.Bookmarks.Exists('VERSIONNR') then
showmessage('Found - Version Nr:
'+WordApp.ActiveDocument.FormFields.Item('VERSIONNR').Result)
else
showmessage('Not Found');

I hope my explanation is sufficient to guide someone to assist me in
this matter.

Thank you in advance!
Marinus
<<<

Try this:

procedure TForm1.Button1Click(Sender: TObject);
const
AWordDoc = 'C:\Test.doc';
wdSaveChanges = $FFFFFFFF;
var
WordApp: OLEVariant;
SaveChanges: OleVariant;
begin
try
WordApp := CreateOleObject('Word.Application');
except
// Error....
Exit;
end;
try
WordApp.Visible := False;
WordApp.Documents.Open(AWordDoc);

//showmessage(WordApp.ActiveDocument.BuiltInDocumentProperties[wdPropert
yTitle].Value);

showmessage(WordApp.ActiveDocument.BuiltInDocumentProperties['VERSIONNR'
].Value);
// ...
// ...
finally
SaveChanges := wdSaveChanges;
WordApp.Quit(SaveChanges, EmptyParam, EmptyParam);
end;
end;

--
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.