How can I edit a Word document without Report Generator?
13 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Kojiro Saito
2020-4-20
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!