S
Stretchcoder
I need to write code (Visual C++ 2005) to add a password (or encryption) to
various types of office files (Without opening the apps for the user to see).
Basically I want the user to enter a password, and if they try to open say a
..doc file later it will look to them like the file was protected in MS Word
watever version is on their PC.
This code must work for versions of Office 2000 and later, and must work
even if Office is not installed on a particular PC.
After stumbling around MS documentation for quite a while, I have had a
terrible time figuring out what dlls and other files I need to include to get
the automation to work for all the various Office apps, and what files will
actually need to reside on the PC with my exe in order for this all to work.
Any suggestions on where I should look to figure this out or a better way to
do it would be greatly appreciated!
I think I have figured out how to do this with Word 2003, it looks something
like:
Word::_ApplicationPtr wordapp;
// create new MS Word instance
wordapp.CreateInstance("Word.Application");
wordapp->Visible = false;
// open document file
_variant_t vtDocFile = filename;
Word::_DocumentPtr pDoc;
pDoc = wordapp->Documents->Open(&vtDocFile);
pDoc->ReadOnlyRecommended = false;
pDoc->Password = password;
pDoc->WritePassword = _T("");
pDoc->Save();
wordapp->Quit();
Thanks for the help!
various types of office files (Without opening the apps for the user to see).
Basically I want the user to enter a password, and if they try to open say a
..doc file later it will look to them like the file was protected in MS Word
watever version is on their PC.
This code must work for versions of Office 2000 and later, and must work
even if Office is not installed on a particular PC.
After stumbling around MS documentation for quite a while, I have had a
terrible time figuring out what dlls and other files I need to include to get
the automation to work for all the various Office apps, and what files will
actually need to reside on the PC with my exe in order for this all to work.
Any suggestions on where I should look to figure this out or a better way to
do it would be greatly appreciated!
I think I have figured out how to do this with Word 2003, it looks something
like:
Word::_ApplicationPtr wordapp;
// create new MS Word instance
wordapp.CreateInstance("Word.Application");
wordapp->Visible = false;
// open document file
_variant_t vtDocFile = filename;
Word::_DocumentPtr pDoc;
pDoc = wordapp->Documents->Open(&vtDocFile);
pDoc->ReadOnlyRecommended = false;
pDoc->Password = password;
pDoc->WritePassword = _T("");
pDoc->Save();
wordapp->Quit();
Thanks for the help!