Hello, my basic applescript skill has got far worse since I started working in vba
I want to find a single paragraph based on a unique style, move it to the start of the document, keeping it’s style
So far i can find it, insert it as the first paragraph but I’m currently stuck with reapplying it’s paragraph style and with deleting the original paragraph
Apologies for being feeble, time is pressing and I have a lot on and I gall at spending a day on something that should be simple (ranges are a vague area for me)
Thanks
tell application "Microsoft Word"
activate
set findRange to find object of selection
-- clear any previous formatting used in a find operation
set all of findRange to true -- find forward
set style of findRange to "ChapterHead" -- the style to look for
tell findRange
set gotIt to execute find find text "" -- do the search w/o matching any text
end tell
if gotIt is true then -- if a match was found
copy object selection -- copy it to the clipboard -- do i have to use the clipboard?
set mySelection to (the clipboard) -- then put clipboard into a variable
insert text mySelection & return at front of text object of active document
--so far so good but how to delete the found range and apply the Chapterhead style to the new first paragraph?
end if
end tell
hmpf, explaining it and making a cup of tea seems to have solved it, the below does what i want, do please suggest a better way, this will run hundreds of times a day and I’m not convinced I need to employ the clipboard, do I?
tell application "Microsoft Word"
activate
set findRange to find object of selection
-- clear any previous formatting used in a find operation
set all of findRange to true -- find forward
set style of findRange to "ChapterHead" -- the style to look for
tell findRange
set gotIt to execute find find text "" -- do the search w/o matching any text
end tell
if gotIt is true then -- if a match was found
copy object selection -- copy it to the clipboard
set mySelection to (the clipboard) -- then put clipboard into a variable
insert text mySelection & return at front of text object of active document
set findRange to first paragraph of active document
set style of findRange to "ChapterHead"
delete the selection
end if
end tell