Writing PDF files - problem with MSWord automation in compiled executable
2 views (last 30 days)
Show older comments
Hi
I'm having a problem getting MSWord automation to work when the code is compiled as an executable
I have a Matlab program that generates an HTML file, as a final step I want to save this as PDF. The function below works fine when running in Matlab, but the executable generated by mcc has an error at the SaveAs2 step. (All the other statements work fine in the executable.)
doc.SaveAs2(pdfFile,17);
--- Attempt to reference field of non-structure array.
I've also tried the alternative syntax which also works in Matlab, but this produces a different error in the executable.
SaveAs2(doc,pdfFile,17);
--- Undefined function 'SaveAs2' for input arguments of type 'double'.
Any suggestions would be greatly appreciated. Thanks Neil Caithness
function html2pdf(htmlFile,pdfFile)
% Open Word
wordApplication = actxserver('Word.Application');
% Uncomment this for debugging
% set(wordApplication,'Visible',1);
% Get a handle to the documents object
documents = wordApplication.Documents;
% Open the Document
doc = documents.Open(htmlFile);
% Save it as PDF
doc.SaveAs2(pdfFile,17);
% Close the document
doc.Close;
% Close Word
wordApplication.Quit;
MATLAB Version 7.12.0.635 (R2011a) MATLAB License Number: xxxx Operating System: Microsoft Windows 7 Version 6.1 (Build 7601: Service Pack 1) Java VM Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot™ 64-Bit Server VM mixed mode
Microsoft Office Professional Plus 2010 Version 14.0.6112.5000 (64-bit)
0 Comments
Accepted Answer
Friedrich
on 31 Jan 2012
Hi,
please make sure that you take care of the path correctly:
Since it works in ML but not compiled, I guess you missed something regarding the paths (in details: I would guess the documents.Open line doesn't work as expected)
Maybe make Word visible so you can see whats going on in the compiled mode. This should help you debugging that issue.
In addition, do you run the compiled application on the same machine where MATLAB is installed? I am not 100% sure but AFAIK the saveas2 method was introduced in Office 2010 and doesn't exist in 2007 and earlier Office verson.
0 Comments
More Answers (0)
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!