read html text from cell with libreoffice basic - libreoffice-basic

For some reason I need retrive "html formated text" from cell in which calc sheet.
I had tried :
Sub Main
Osheet = ThisComponent.Sheets.getByName("mySheet")
oCell = oSheet.getCellrangeByName("D2")
Print oCell.htmlText REM there is no htmltext property in cell instance
REM holp output some thing like <p color="#ff0000">text in cell</p>
End Sub
Is's possible to do this?
-----------update-------------
as image show above. I change color and the font size in cell.
then I need to retrive "html text" from the cell with VBA.
if possible It should output:
<font size='12'>Hi !<font color='#ff0000'>every</font><font size='16'>body</font>.<font color='#0000ff'>Are</font> you OK?</font></font>
How to implement this function with VBA?

Related

Copy text and picture into new word document

In the active word document I have a macro which extracts a text string and all images from the document.
I want to copy this text and the picture in a new blank word document.
I tried the following
Dim docNew As Document
Set docNew = Documents.Add
With ThisDocument
...
docNew.Content.Text = docNew.Content.Text & vbCrLf & sSentence
For Each iShape In .InlineShapes
iShape.Select
Selection.CopyAsPicture
docNew.Content.Paste
Next iShape
End With
When I execute this code, first the text is copied correctly to the new blank document. But when the picture is pasted, it overwrites the text and only the picture remains in the document.
How do I have to modify the code so that the text as well as all pictures are included?
As you would have discovered from looking at the help text .Content represents the whole of the main body of the document.
Assuming you want to add the pictures at the end of the document, replace
docNew.Content.Paste
with
With docNew.Content
.InsertParagraphAfter
.Paragraphs.Last.Range.Paste
End With

Ignore Text Boxes on Spellcheck

I’m trying to create a macro that will only spellcheck specific cells. I have succeeded in spellchecking the cells, but for some reason the spellcheck wizard keeps running afterwards and tries to check any text boxes on my spreadsheet.
Below is the code:
Range(“C8”).Select
Selection.CheckSpelling SpellLang:=1034
Updating code with suggestions, however the code is still spellchecking text boxes:
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
Const dummyCell = "Z999" 'address of an empty cell
Dim cellsToCheck As Range
Set cellsToCheck = ws.Range("C8")
Union(Range(dummyCell), cellsToCheck).CheckSpelling
I cycled through and it is spellchecking the text boxes before the actual range specified in "CellsToCheck".
Programmatically check spelling of a single cell without the dialog box
If you want to programmatically check the spelling on a single cell, and you don't want the Spelling dialog box to display you can use the CheckSpelling method as it applies to the Application object.
Sub checkSpelling_NoDialog()
Dim correctlySpelled As Boolean, textToCheck As String
textToCheck = Range("A1")
correctlySpelled = Application.checkSpelling(textToCheck)
If Not correctlySpelled Then
MsgBox "Incorrect Spelling of: " & textToCheck
Else
MsgBox "Correct Spelling of: " & textToCheck
End If
End Sub
Programmatically check spelling of a single cell with the dialog box
If you do want the Spelling dialog box to display but only want to check one cell, you need to "trick Excel". Excel is designed to, if you've only selected one cell, assume you actually want to check the entire worksheet.
Sub checkSpelling_WithDialog()
Const dummyCell = "Z999" 'address of an empty cell
Dim cellsToCheck As Range
Set cellsToCheck = Range("A1")
Union(Range(dummyCell), cellsToCheck).checkSpelling
End Sub
More information on the CheckSpelling method is outlined here and here.

Convert Figure Alt Description to Picture Caption in Word

I need a way to get an image's Alt Description (specified in HTML) into the Word DOCX image's Caption. This needs to be done with many images in a document, so a macro would be best.
Assume an HTML doc with an img tag similar to this
<img src="http://www.example.com/path/to/image/picture01.jpg"
title="picture 01 title"
alt="this is alt text"
caption="this is a caption field">
This HTML doc is imported into Word 2010 (via File, Open). The image will show in the doc.
Now, how to get the 'title' attribute (which shows up in the Format Picture's Alt-Text dialog as the Description - see screenshot below) into the image's Caption?
Note that the caption parameter in the image tag is not converted to a Word Caption for that image.
Sample Alt-Text dialog for an image which shows the image's alt value as the Description
Microsoft Word has a Range.InsertCaption method, which will insert field codes to automatically number images. As you were asking to insert Alternative Text, my feeling is you were using the term caption simply as a directive to get the text beneath each image on its own carriage return. So that's what this code does:
Sub GenerateAltTextCaptions()
Dim AltTextCaption As String
Dim ImageRange As Range
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst
With ActiveDocument
For i = 1 To .InlineShapes.Count
AltTextCaption = .InlineShapes(i).AlternativeText
Set ImageRange = .InlineShapes(i).Range
ImageRange.Collapse Direction:=wdCollapseEnd
ImageRange.InsertAfter vbCr
ImageRange.InsertAfter AltTextCaption
Next
End With
End Sub
Yes, I think you've hit on a good way to make the conversion. Glad you were able to find it!
The code below will loop all the InlineShapes in the document and, if the Alternative Text is not empty, create a caption using that text.
InsertCaption is only available in VBA for InlineShapes. The user can insert captions for Shapes (graphics with text wrap formatting) because Word evaluates the selected graphic and creates a Textbox of the same width and positions it immediately below the graphic. The Shape and textbox are not, however, linked together in any way. So this functionality is not offered in VBA and would require some "creative" programming.
Sub InsertCaptionFromAltText()
Dim doc as Word.Document
Dim ils As word.InlineShape
Dim captionText As String
Set doc = ActiveDocument
Set ils = doc.InlineShapes(1)
For each ils in doc.InlineShapes
captionText = ils.AlternativeText
If Len(captionText) > 0 Then
ils.Range.InsertCaption Label:=wdCaptionFigure, _
Title:=captionText, _
Position:=wdCaptionPositionBelow
End If
Next
End Sub

Old text in one color, new text in another color. Excel VBA

Each day there is a new worksheet where I write some notes. I would like to have a button that creates a new worksheet everyday, puts the old text in black and when I start writing new text (can be in a cell with text already) it should be blue.
Is there a way to do that? I can use VBA as well.
Whenever you run it, the cells with values on the activesheet will be blue and on the empty cells you will be writing in black:
Public Sub TestMe()
Cells.Font.Color = vbBlack
ActiveSheet.UsedRange.Font.Color = vbBlue
End Sub

VSTO VB.NET Excel Chart, Subtitle for Chart - How to access chart text box from code?

I have a chart in Excel that I'd like to use a subtitle on. There is no SubTitle Property on the chart object, so I looked in the Excel User interface and found that you can only create a sub-title by using a text box. The text box looks like its associated with the chart, not the worksheet, so how would I access that text box from code?
Thanks...
There is another possibility, and that is to include the subtitle in the chart title, for example:
Dim co As ChartObject
Set co = Sheet1.ChartObjects(1)
co.Chart.HasTitle = True
co.Chart.ChartTitle.Text = "First Quarter Sales" & vbCrLf & "Subtitle"
co.Chart.ChartTitle.Characters(22, 8).Font.FontStyle = "Bold Italic"