Cloning Word Document

Add-in Express™ Support Service
That's what is more important than anything else

Cloning Word Document
Cloning document in-place without opening new Word window 
Leon H H




Posts: 43
Joined: 2010-04-06
Is it possible to load original document Docu1.docx and then click on the custom ribbon button that will do the following:
- "Save As" the original document to a different location on HD, and therefore, the loaded document will become Docu2.docx, all that without prompting the user for new location/doc name?

Please ignore this - I found the answer:
[CODE]Word.Document newDoc = null;

try
{
newDoc = WordApp.ActiveDocument;
if (newDoc.ProtectionType == Word.WdProtectionType.wdNoProtection)
{
WordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
string fileName = Path.GetFileNameWithoutExtension(newDoc.FullName) + " - Clone";
string filePath = Path.Combine(Path.GetDirectoryName(newDoc.FullName), fileName);
newDoc.SaveAs2(filePath);
WordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsAll;
}
else
{
MessageBox.Show("The document is protected. Enable editing and try again.", Properties.Settings.Default.AppTitle,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
catch(Exception ex)
{
Log.Verbose(ex);
}
finally
{
if (newDoc != null)
Marshal.ReleaseComObject(newDoc);
}
Posted 14 Oct, 2022 20:34:22 Top
Andrei Smolin


Add-in Express team


Posts: 18806
Joined: 2006-05-11
Thank you for providing a solution!

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Oct, 2022 06:06:58 Top