Ask Your Question
0

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

asked 2015-04-08 21:41:30 +0200

TJacobs gravatar image

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!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2015-04-09 14:26:51 +0200

pierre-yves samyn gravatar image

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
edit flag offensive delete link more

Comments

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!

TJacobs gravatar imageTJacobs ( 2015-04-09 16:48:27 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-04-08 21:41:30 +0200

Seen: 81 times

Last updated: Apr 09 '15