How do I get a LO macro to stop when it finds an invalid autotext shortcut?

I’m trying to create a macro that goes down a list of bullet points, the first word of each of which is an Autotext shortcut, and opens each shortcut. I have it set up to do this for 10 bullets, but sometimes I only have 1 or 2. I would like the macro to stop the first time it gets to an invalid autotext shortcut (when it’s at the end of the list).

I want to put something like this above each macro section:
If (autotext entry not found) Then
Stop
Else

Anyone know how to write the “autotext entry not found” part?

Thanks!

Hi - Below are two examples: test with shortcut and with the name.

Adapt the Category name and Shortcut to the interface language.

These procedures return either #N/A if the AutoText is not found or the text. Regards.

option explicit

sub main

msgbox PysAutoTextByShortCut("standard", "AR"), 64, "AutoText"
msgbox PysAutoTextByName("standard", "Acknowledgement of Receipt"), 64, "AutoText"

end sub

function PysAutoTextByName(sCat as string, sName as string) as string

dim oAutoTextContainer as object, oGroup as object, oEntry as object, i as integer

oAutoTextContainer = CreateUnoService("com.sun.star.text.AutoTextContainer")
PysAutoTextByName = "#N/A"

if oAutoTextContainer.hasByName(sCat) then
	oGroup = oAutoTextContainer.getByName(sCat)
	for i = 0 to ubound(oGroup.Titles)
		if oGroup.Titles(i) = sName then
			oEntry = oGroup.getByIndex(i)
			PysAutoTextByName = oEntry.string
			exit for
		end if
	next i
end if

end function

function PysAutoTextByShortCut(sCat as string, sSC as string) as string

dim oAutoTextContainer as object, oGroup as object, oEntry as object

oAutoTextContainer = CreateUnoService("com.sun.star.text.AutoTextContainer")
PysAutoTextByShortCut = "#N/A"

if oAutoTextContainer.hasByName(sCat) then
	oGroup = oAutoTextContainer.getByName(sCat)
	if oGroup.hasByName(sSC) then
		oentry = oGroup.getByName(sSC)
		PysAutoTextByShortCut = oEntry.string
	end if
end if

end function

OK, that is definitely a step closer, but how would I get this to just run the AutoText (if it exists) or quit the macro (if it doesn’t) in the document rather than having a messagebox pop up? Thanks!