Hi Peerapol,
Thank you for your question.
In fact, the approach demonstrated in the sample is based on using the
Word Object Model - the same model that is available for VBA macros.
Both the insertion point (text cursor location) and the selection in the Word Object model is represented by the
Selection objects. This object contains a Range that can be used in a way that is very similar to the approach demonstrated in the sample.
Here is a sample code that demonstrates how to add some text right after the text cursor:
private void insertTextAtSelection(_DocumentImpl document, String text, int fontSize){
Window activeWindow = document.getActiveWindow();
Selection selection = activeWindow.getSelection();
Range range = selection.getRange();
try {
//selection.typeText(new BStr(text));
range.setText(new BStr(text));
_Font font = range.getFont();
try {
font.setSize(new SingleFloat(fontSize));
}
finally {
font.setAutoDelete(false);
font.release();
}
range.insertParagraphAfter();
}
finally {
range.setAutoDelete(false);
range.release();
selection.setAutoDelete(false);
selection.release();
activeWindow.setAutoDelete(false);
activeWindow.release();
}
}
Regards,
Natasha