Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-02-2018, 09:22 PM
raywood raywood is offline Divide Text Doc into Multiple Parts at .pa Delimiter Windows 10 Divide Text Doc into Multiple Parts at .pa Delimiter Office 2010 64bit
Novice
Divide Text Doc into Multiple Parts at .pa Delimiter
 
Join Date: Sep 2018
Posts: 10
raywood is on a distinguished road
Default Divide Text Doc into Multiple Parts at .pa Delimiter

I have a number of text documents that have .pa where manual page breaks should be. If memory serves, that was how we did manual page breaks in XyWrite.



I'd like to develop a macro that would use those .pa delimiters as document ending points. So there would be some text; the macro would grab that text, down to the first occurrence of .pa, and move it to a new file; that first occurrence of .pa would itself be deleted; the newly created file would be saved with some automatic name; and the process would repeat, down to the (new) first occurrence of .pa, until the original file was empty.

I've used Word macros, but I don't know a lot about them. After some digging, I found this, and tried to modify it to fit, but I don't know what to substitute for " ActiveDocument.Bookmarks."

Code:
Sub BreakOnPage()
   ' Used to set criteria for moving through the document by page.
   Application.Browser.Target = wdBrowsePage

   For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
      
      'Select and copy the text to the clipboard
      ActiveDocument.Bookmarks(".pa").Range.Copy

      ' Open new document to paste the content of the clipboard into.
      Documents.Add
      Selection.Paste

      ' Removes the break that is copied at the end of the page, if any.
      Selection.TypeBackspace
      ChangeFileOpenDirectory "D:\"
      DocNum = DocNum + 1
      ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
      ActiveDocument.Close

      ' Move the selection to the next page  in the document
      Application.Browser.Next
   Next i
   ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
Reply With Quote
 

Tags
macro, page break, split



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to divide a landscape page into 2 parts rtcary Word 1 01-17-2018 12:07 AM
One long string of text with ; as the delimiter Laurie B. Excel 1 02-28-2015 03:02 AM
Divide Text Doc into Multiple Parts at .pa Delimiter Split file using variable delimiter kramer74 Word VBA 7 09-01-2014 12:12 AM
How do I edit text in Quick Parts? TommyVincent Word 4 07-30-2014 01:51 PM
divide page into 4 parts aclark17 Word 4 01-17-2012 09:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:56 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft