How can I use the GoTo-command to go to a Bookmark in a word document using actxserver
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
we create an extensive word document as a result of our data analysis which can be up to 100 pages long by using the WriteToWordFromMatlab function from the Mathworks File Exchange. Depending on the dataset we are analyzing, the chapters and sub-chapters can vary.
What I want to do is to move around in the word document freely. We are already using this to go back the table of contents after the word document is written and write it.
I checked the VBA documentation on the GoTo method and the WdGoToItem command:
From the lists available there I conclude that the only way to go to a specific point in our document would be to use bookmarks. This would allow us to set bookmarks while creating the word document and then, later on, go to that specific bookmark using its unique name.
However, when testing the GoTo method, I ran into the problem that I can use all options from the table above (numbers 0 to 15), but using -1 (the number for bookmarks) always returns an error message. The code I am using is:
word_connector.Selection.GoTo(-1,1,1,'Evaluation')
Which returns the error message
Error using Interface.Microsoft_Word_15.0_Object_Library.Selection/GoTo
I have no idea how to change the code as all other numbers work fine. Help is much appreciated.
Best regards, Frederik
0 comentarios
Respuestas (2)
Jeffery Devereux
el 30 de Oct. de 2018
word_connector.Selection.GoTo(-1,0,0,'Evaluation')
Try this...
1 comentario
virup Rao
el 25 de Jul. de 2019
Editada: virup Rao
el 25 de Jul. de 2019
I am using matlab 2018a and word 2010.
I have tried this but no use..any other alternative to Goto the already set bookmarks in the document.
I would also need to set bookmarks to a specific text box or cell in the table.
If anybody can help.
Jeffery Devereux
el 25 de Jul. de 2019
COMM = actxserver('Word.Application');
wdoc = COMM.Documents.Open([pwd '\Documents\YourWordDOC.docx']);
TH2 = [];
Headers = {'EmDes','DigModType','DigBitRate','NumDigStates','OccBW'};
Data = ??
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function InsertTableAtCursor(Data,Headers,COMM,BookMark,TH2)
[NoRows,NoCols] = size(Data);
TableData = Data;
TableHeader = Headers;
Doc = COMM.Selection;
Doc.Paragraphs.Alignment = 0;
Doc.Font.Name = 'Arial';
Doc.Font.Size = 7;
Doc.Font.Bold = 1;
Doc.Font.ColorIndex = 'wdBlack';
Doc.GoTo(-1,0,0,BookMark);
Table1 = WordCreateTable(COMM,NoRows,NoCols,TableData,1,TableHeader);
Table1.Columns(1).AutoFit
if ~isempty(TH2)
Table1.Cell(1,1).Range.Text = 'XXXXXXX';
A = Table1.Cell(1,1).Range;
Table1.Rows.Add(A);
Table1.Cell(1,2).Merge(Table1.Cell(1,3));
Table1.Cell(1,2).Merge(Table1.Cell(1,3));
Table1.Cell(1,2).Merge(Table1.Cell(1,3));
Table1.Cell(1,3).Merge(Table1.Cell(1,4));
Table1.Cell(1,3).Merge(Table1.Cell(1,4));
Table1.Cell(1,3).Merge(Table1.Cell(1,4));
Table1.Cell(1,4).Merge(Table1.Cell(1,5));
Table1.Cell(1,4).Merge(Table1.Cell(1,5));
LTH2 = length(TH2);
for j = 1:LTH2
Table1.Cell(1,j).Range.Text = TH2{j};
Table1.Cell(1,j).Range.ParagraphFormat.Alignment = 1;
end
end
Table1.Rows.Alignment = 1;
Table1.Range.Font.Size = 7;
Table1.AllowAutoFit = 1;
end
0 comentarios
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!