How can I edit a Word document without Report Generator?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sara Martos
am 20 Apr. 2020
Kommentiert: Sara Martos
am 20 Apr. 2020
Hello!
I would like to be able to edit an existing Word document without using Report Generator tool.
I have seen a file that use invoke instruction to open the Word document but I have a error.
Invoke instruction looks for the document in System32 folder but I need it searches in a specific address.
clear all
word = actxserver('Word.Application'); %Start Word
WordFileName='prueba.docx';
hdlWordDoc = invoke(word.Documents,'Open', WordFileName); %Open Document
selection=word.Selection; %set cursor
selection.Pagesetup.LeftMargin=28.34646; %set left Margin to 1cm
selection.TypeText('Hello World!'); %write Text
word.Visible =1;
Error is:
Error using Interface.0002096C_0000_0000_C000_000000000046/Open
Invoke Error, Dispatch Exception:
Source: Microsoft Word
Description: We could not find the file. Has it been moved, renamed or deleted?
(C:\WINDOWS\system32\prueba.docx)
Help File: wdmain11.chm
Help Context ID: 604e
Error in Prueba5 (line 5)
hdlWordDoc = invoke(word.Documents,'Open', WordFileName);
Thanks a lot.
0 Kommentare
Akzeptierte Antwort
Kojiro Saito
am 20 Apr. 2020
As you know, the current directory of Word calling from actxserver is C:\WINDOWS\system32, so you need to set a fullpath of the docx file.
word = actxserver('Word.Application'); %Start Word
WordFileName = [pwd filesep 'prueba.docx'];
hdlWordDoc = invoke(word.Documents,'Open', WordFileName); %Open Document
Or, instead of invoke, you can use the following codes.
word = actxserver('Word.Application'); %Start Word
WordFileName = [pwd filesep 'prueba.docx'];
Docs = word.Documents;
Doc = Docs.Open(WordFileName);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!