Ask Your Question

Check for style and font in basic [closed]

asked 2015-09-19 13:09:07 +0100

Pansmanser gravatar image

I have a Basic macro, called from Calc but creating a Writer document, which sets a paragraph style, page style (PageDescName) and font, which I have defined. If any is missing and error arises. Can I check for the existence of these properties before setting them?

oCursor = oFrame.Text.createTextCursor()
oCursor.PageDescName = "FaxDiary"
oCursor.ParaStyleName = "FaxDiary"
oCursor.CharFontName = "Moon Phases"
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-03-20 01:25:41.120978

1 Answer

Sort by » oldest newest most voted

answered 2015-09-19 18:11:52 +0100

Pansmanser gravatar image

updated 2015-09-19 19:10:08 +0100

OK, I have a solution to the Style parts of the question. For paragraph style a trap might look like this:

If Not oFrame.StyleFamilies.getByName("ParagraphStyles").hasByName("FaxDiary") Then
  MsgBox "Paragraph style 'FaxDiary' is not present. Exiting" : Exit Sub

And likewise for page style:

If Not oFrame.StyleFamilies.getByName("PageStyles").hasByName("FaxDiary") Then
  MsgBox "Page style 'FaxDiary' is not present. Exiting" : Exit Sub

I also have a solution to the font question, based on Andrew Pitonyak's OOME listing 299. It seems relatively cumbersome, and I wonder if one cannot access the font list directly. Or even access the Frame (already defined and used above).

oFonts() = ThisComponent.getCurrentController().getFrame.getContainerWindow().getFontDescriptors()
Moon = False
For i = LBound(oFonts()) To UBound(oFonts())
  If oFonts(i).Name = "Moon Phases" Then Moon = True
If Not Moon Then MsgBox "Font 'Moon Phases' is not present. Exiting." : Exit Sub
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-09-19 13:09:07 +0100

Seen: 335 times

Last updated: Sep 19 '15