Save document with custom properties with actxserver Word
조회 수: 10 (최근 30일)
이전 댓글 표시
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
Umar
2024년 7월 11일
Hi Philipp,
Mario just posted a comment about resolving this issue. Please try his suggested solution and update us about test results.
답변 (1개)
Mario Malic
2024년 7월 10일
댓글 수: 4
Mario Malic
2024년 7월 15일
The flag is not ment to be used for these purposes, so it's better to remove it.
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!