Azzera filtri
Azzera filtri

Save document with custom properties with actxserver Word

65 visualizzazioni (ultimi 30 giorni)
Philipp
Philipp il 10 Lug 2024 alle 8:50
Commentato: Mario Malic il 15 Lug 2024 alle 22:28
The following script shall change custom properties of a word document using the activexserver syntax for Microsoft Word.
%% Initiallize Word Connection
hdlWord = actxserver('Word.Application');
hdlWord.Visible = true;
%% File and Location
fullLocation = 'C:\Users\Name\Documents\MATLAB\PropTest.docx';
hdlDoc = hdlWord.Documents.Open(fullLocation);
%% Property Change
hdlProp = get(hdlDoc.CustomDocumentProperties, 'Item', 'Property1');
get(hdlProp,'Value');
set(hdlProp,'Value','nice'); % saved as "jealous" before running the script
%% Save Doc
hdlWord.ActiveDocument.SaveAs2(fullLocation)
hdlDoc.Close();
hdlWord.Quit();
The property change itself is working. Sadly, the script is not saving the document. There is no error or warning given out.
If I comment the close functions and click save manually it works fine.
If I save the document as a another file the properties are changed and saved. Therefore, a work around by deleting and renaming and so on would work.
Could someone help me out on how to save the opened document and close it by script?
  5 Commenti
Philipp
Philipp il 11 Lug 2024 alle 6:43
Hi Umar,
the pause function is not helping. Neither using Doc.Save(); nor using .SaveAs2();
FYI: I used a tempfile as work around. Saving to a new temp file, then deleting the original one. Renaming the temp file to the original name.
Umar
Umar il 11 Lug 2024 alle 6:56
Hi Philipp,
Mario just posted a comment about resolving this issue. Please try his suggested solution and update us about test results.

Accedi per commentare.

Risposte (1)

Mario Malic
Mario Malic il 10 Lug 2024 alle 16:06
  4 Commenti
Mario Malic
Mario Malic il 15 Lug 2024 alle 7:38
The flag is not ment to be used for these purposes, so it's better to remove it.
Mario Malic
Mario Malic il 15 Lug 2024 alle 22:28
If the answer solved your problem, it should be marked as accepted.

Accedi per commentare.

Prodotti


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by