this is an example which saves the first 4 paragraphs of the active document into a new document “para_1-4.doc” on desktop. Might be a starting point
property paraFrom : 1
property paraTo : 4
set pathToDesktop to (path to desktop as text)
tell application "Microsoft Word"
set myRange to create range active document start (start of content of ¬
text object of paragraph paraFrom of active document) end (end of content ¬
of text object of paragraph paraTo of active document)
select myRange
copy object selection
set newDoc to make new document
paste object text object of newDoc
save newDoc in pathToDesktop & "para_1-4.doc"
close front document
end tell
Well, I will reformulate my question as nobody replied…
With a MS Word 2011 document & AppleScript, how can I:
Count the number of pages?
Or (best) count the number of page breaks?
How may I loop thru the pages and get a certain paragraph text at the top a each page?
Thanks for the help. I tried looking at the Word 2004 AppleScript Reference but for me, it seems much more understandable to do it using VBA… But anyway, I want to find my way with AppleScript.
I am desperate to find a solution with AppleScript…
Below is an example with VBA that lets me get and iterate thru the sections of my Word document.
With the command: ActiveDocument.Sections.Count, in VBA I am able to loop thru the sections of my active document.
How do I do this with AppleScript?
Please help me!!!
Thanks in advance for the help.
Andrew
Sub couper_sections()
Application.Browser.Target = wdBrowseSection
For i = 1 To ((ActiveDocument.Sections.Count) - 1)
ActiveDocument.Bookmarks("\Section").Range.Copy
Documents.Add
Selection.Paste
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "Macintosh HD"
DocNum = DocNum + 1
ActiveDocument.SaveAs fileName:="Test_" & DocNom & ".docx"
ActiveDocument.Close
Application.Browser.Next
Next i
set NbSections to 0
set Compteur to 0
set pathToDesktop to (path to desktop as text)
tell application "Microsoft Word"
set NbSections to count sections of active document
repeat with Compteur from 1 to NbSections
set myRange to create range active document start (start of content of text object of section Compteur of active document) end (end of content of text object of section Compteur of active document)
select myRange
copy object selection
set newDoc to make new document
paste object text object of selection
set fileName to get content of text object of paragraph 2 of newDoc
save newDoc in pathToDesktop & fileName & ".docx"
close front document
end repeat
end tell
Any coments or suggestions about this work?
Is there some bad coding?
Things wrong?