Converting text to hyperlink

I wish to write a CALC Basic macro that will do the same as F2(edit cell)

The result is to create a hyperlink as the text in the cell is an email address.

I don’t know precisely what you want to achieve. Doing exactly as you describe doesn’t seem to be possible.
If you want to apply the “macro” to single selected cells you can assure for that they contain correct mail addresses, you can use the code below.
What good for?

Sub convertCellContentToLinkForSingleSelectedCell(Optional pEvent As Object, Optional pPre As String)
theDoc         = ThisComponent
If NOT theDoc.supportsService("com.sun.star.sheet.SpreadsheetDocument") Then Exit Sub
theSelC        = theDoc.CurrentSelection
If NOT theSelC.supportsService("com.sun.star.sheet.SheetCell") Then Exit Sub
If NOT (theSelC.Type=2) Then Exit Sub
content        = theSelC.String
If IsMissing(pPre) Then pPre = "mailto:"
If NOT isUrlSyntax(content, pPre) Then Exit Sub
UrlField       = theDoc.createInstance("com.sun.star.text.TextField.URL")
UrlField.Representation = theSelC.String
UrlField.URL   = pPre & content
theDoc.UndoManager.EnterUndoContext("Linkify")
theSelC.String = ""
tCur           = theSelC.createTextCursorByRange(theSelC.Start)
theSelC.insertTextContent(tCur, UrlField, False)
theDoc.UndoManager.LeaveUndoContext
End Sub

Function isUrlSyntax(pText As String, pPre As String) As Boolean
REM This Function does not check the content of the cell for the syntax of mail addresses!
REM Write a respective body for the function if needed.
isUrlSyntax = (pText<>"")
End Function

Thank you very much

Sub convertCellContentToLinkForSingleSelectedCell(Optional pEvent As Object, Optional pPre As String)

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

theDoc         = ThisComponent
If NOT theDoc.supportsService("com.sun.star.sheet.SpreadsheetDocument") Then Exit Sub
theSelC        = theDoc.CurrentSelection
If NOT theSelC.supportsService("com.sun.star.sheet.SheetCell") Then Exit Sub
If  (theSelC.Type=2) Then
	content        = theSelC.String
	If IsMissing(pPre) Then pPre = "mailto:"
	If isUrlSyntax(content, pPre) Then
		UrlField       = theDoc.createInstance("com.sun.star.text.TextField.URL")
		UrlField.Representation = theSelC.String
		UrlField.URL   = pPre & content
		theDoc.UndoManager.EnterUndoContext("Linkify")
		theSelC.String = ""
		tCur           = theSelC.createTextCursorByRange(theSelC.Start)
		theSelC.insertTextContent(tCur, UrlField, False)
		theDoc.UndoManager.LeaveUndoContext
	end if
end if
dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = "By"
args3(0).Value = 1
args3(1).Name = "Sel"
args3(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args3())

End Sub

Function isUrlSyntax(pText As String, pPre As String) As Boolean
REM This Function does not check the content of the cell for the syntax of mail addresses!
REM Write a respective body for the function if needed.
isUrlSyntax = (pText<>"")
End Function

sub doit
while true

convertCellContentToLinkForSingleSelectedCell

wend
end sub