Using macro to switch styles back and forth?

Keyboard macros or custom scripts

Using macro to switch styles back and forth?

Postby kharrisma » Thu Jan 21, 2021 4:46 pm

Hi Forum Folke,

Perhaps a naive question, but: is it possible to create a keyboard macro (such as CTRL+ALT+F3) or something like that (a 'la 'word perfect') so I can frequently shift back and forth between several different types of paragraph styles?

My intended document consists of emails (left-justified, but with indented edges on each side, so it forms a 'column' centered in the page), texts from (left justified up against left margin, but restricted to left 2/3 of page, and enclosed in a yellow callout balloon), texts to (left justified, but starting about a third of a page from the left margin, and ending at the right margin, enclosed in a blue callout balloon), and default (but center justified) text.

I have been jumping back and forth from the "styles and formatting" floating toolbar, but I have to scroll up and down the entire list of styles to find the ones I am constantly using. It's do-able, but highly tedious. I'd like to create four (at least) key combinations that will do this quickly... or is there a way to get the "styles and formatting" toolbar to show only those styles I'm actually using?

Thanks in advance, and apologies if I've posted this question in the wrong place!
OpenOffice 4.1.6. on Windows 10 (ecchhh!) and Linux Mint
kharrisma
 
Posts: 38
Joined: Thu Nov 03, 2011 12:39 am
Location: New Hampshire, USA

Re: Using macro to switch styles back and forth?

Postby FJCC » Thu Jan 21, 2021 5:19 pm

At the bottom of the Styles and Formatting dialog there is a drop down list. It probably says All Styles in your case. You can set that to Applied Styles and show only the styles you are using.

It is also possible to map styles to key board combinations. Select the menu item Tools -> Customize and choose the Keyboard tab. At the bottom left, scroll down the Category list to find Styles. Expand the Styles list and choose Paragraph. Choose the desired style from the Function list. You can then choose a key combination from the list of those and click Modify to assign it.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 8121
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Using macro to switch styles back and forth?

Postby JeJe » Thu Jan 21, 2021 5:26 pm

You can also name your custom styles so they start with the letter A and appear at the top of the list.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1537
Joined: Wed Mar 09, 2016 2:40 pm

Re: Using macro to switch styles back and forth?

Postby JeJe » Thu Jan 21, 2021 5:41 pm

if you want something like a keypress that switches between a sequence of styles - (screenwriting software typically use the tab key for this) then this is a macro for that. You'd need to change the style names to yours and set a shortcut to the macrol

Code: Select all   Expand viewCollapse view
Sub changestyle
      dim sname,newst as string
      on error goto hr
      sname = ThisComponent.CurrentController.ViewCursor.ParaStyleName
      Select Case sname
      Case "Description"
         newst = "SLUG"
      CASE "SLUG"
         newst = "CHARACTER"
      case "CHARACTER"
         newst = "Parenthesis"
      CASE "Parenthesis"
         newst = "Dialogue"
      case   "Dialogue"
         newst = "Description"
      end select

      if newst <> "" then
         ThisComponent.CurrentController.ViewCursor.ParaStyleName = newst
      end if
      hr:
End Sub

Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1537
Joined: Wed Mar 09, 2016 2:40 pm

Re: Using macro to switch styles back and forth?

Postby kharrisma » Fri Jan 22, 2021 4:59 pm

Thank you All for your replies!

@FJCC... that sounds exactly like what I want to do! Thanks so much for the directions!

@JeJe... I've used that trick elsewhere... using a leading "." or letter or some other character to force it to the top of a list. Don't know why that didn't occur to me here. I also like your code, but that's well above my pay grade. I've been using these things since the '286-12 with a whopping 1mb of RAM and a 40 mb hard drive, running DOS 3.3 was considered killer hardware... but I've never learned how to code. Not even Basic. My mind just isn't wired for it... all it does is generate a bunch of frustration, and who needs that? My talents lie elsewhere. I like the idea, but I wouldn't know which term to alter and what to not touch.
OpenOffice 4.1.6. on Windows 10 (ecchhh!) and Linux Mint
kharrisma
 
Posts: 38
Joined: Thu Nov 03, 2011 12:39 am
Location: New Hampshire, USA


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 3 guests