actxserver makes a word document with a table of contents and i want to the table of contents to be a hyperlink to each section

8 views (last 30 days)
I have created a matlab file that takes in a series of .xlsx files and using the actxserver functions creates a word docuement and fills it with a bunch of sections that each contain some number of graphs created using the .xlsx data. I have got it so that the MATLAB script creates the word document with a Table of Contents as there are quite a few sections. What i want now is to make each section listed in the table of contents a hyperlink to that section. I have used the UseHyperlink = True code but that has made no change. The Word document created is saved as both a word file and a PDF. I would like to have the hyperlinks working in both the Word and the PDF if possible.
  8 Comments
dpb
dpb on 27 Jun 2024
Edited: dpb on 1 Jul 2024
Here's the <link to the .Add method for a TOC> from the Word VBA reference.
You'll want to work your way back from the details to the general TOC info first, but there's everything there is that can be controlled programmatically via VBA, ergo ActiveX.
Good luck, if you thought the Excel object model was complicated, you ain't see'ed nuthin' yet when dig into Word.
ADDENDUM
"[Y]ou cannot always use the exact VBA code because many of the methods are composite methods at the VBA syntax level and Word macros have the VBA compiler to translate to actual code. But, working in MATLAB directly, the VBA compiler is not available"
Note especially that in looking at the example in the above VBA doc, in MATLAB using ActiveX, you cannot use named parameters as it does; the arguments to functions must be passed positionally. Any not needed in the argument list prior to one that is needed must be either passed with explicit values (look up default) or with an empty placeholder, [].
Also, one often must create a temporary variable that is the correct object type of which the method or property is a member so that "dot" addressing is only one level deep; the MATLAB parser doesn't know about possible dereferencing the VBA compiler will do so must help it along. Also, occasionaly one has to resort to using invoke to call a method; sometimes no other syntax seems to work; I've not ever been able to fully understand why in those cases, but it is all tied into what the VBA compiler does internally with VBA source code that simply isn't available to the MATLAB parser.
dpb
dpb on 28 Jun 2024
Edited: dpb on 30 Jun 2024
"...using the actxserver functions creates a word docuement and fills it with a bunch of sections ..."
Post the code you're using that does this and a sample (smallish) Word file that it works on--you may have to "cheat" to attach the Word file by renaming it to Word.txt to get around the forum restrictions.
The doc for the TOC and some responses on the MS support forum indicate the TOC is hyperlinked by default but it notes in response to several Q? about "Why isn't my...?" that you may need to use Ctrl-Click instead of just clicking on some platforms.

Sign in to comment.

Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!