Save to individual ducuments after an ms word mailing

Hello,

I have a long Word document created thru a mailing.

I would like to break up this big document and save each individual letters to disk.

Would this be possible using AppleAcript & MS Word?

Does someone have a similar script that I could use as a starter?

Thanks

Best regards

Andrew

Hi,

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

Hello Stefan,

Thanks for your help.

I would like to work with the pages of my Word document. And be able to do something like this:

set nbPages to count each pages of active document

But how can I find out what objects are at my disposal to be counted? => I don’t see such a thing as “pages”?

Thanks for helping me!

Andrew

Hello to all,

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.

Thanks in advance for any help.

Best regards.

Andrew

Hello again,

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

End Sub

Voilà , I finally made it…


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?

Thanks for the feedback!