Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2017, 02:40 PM
macropod's Avatar
macropod macropod is offline Save each split document with name from inside that document Windows 7 64bit Save each split document with name from inside that document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,518
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It appears from your code that the pages are separated by manual page breaks, in which case you could use Find/Replace to change them to Section breaks, then use the 'Split Merged Output to Separate Documents' macro in the Mailmerge Tips and Tricks thread (https://www.msofficeforums.com/mail-...ps-tricks.html) to do the splitting and renaming. That, of course, assumes the text containing your preferred names is in a consistent location on each page.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 04-13-2017, 01:41 AM
mihnea96 mihnea96 is offline Save each split document with name from inside that document Windows 7 32bit Save each split document with name from inside that document Office 2010 32bit
Novice
Save each split document with name from inside that document
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default

In this situation I have 933 Q&As and it generates ~933 documents (but I have other documents with more than 10.000). My question was if there is any VBA code for extracting text from the document and use it as a name for that document, as I cannot install any macros. I mean, what should i write instead of this:

'build a new sequentially-numbered file name based on the original multi-paged file name and path
strNewFileName = Replace(docMultiple.FullName, ".doc", "_" & Right$("000" & iCurrentPage, 4) & ".doc")
ActiveDocument.SaveAs2 FileName:= _
"TEXT FROM INSIDE" _
, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=14 'save the new single-paged document


Thank you very much!
Reply With Quote
  #3  
Old 04-13-2017, 02:09 AM
macropod's Avatar
macropod macropod is offline Save each split document with name from inside that document Windows 7 64bit Save each split document with name from inside that document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,518
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by mihnea96 View Post
My question was if there is any VBA code for extracting text from the document and use it as a name for that document, as I cannot install any macros.
Without wanting to place too fine a point on it, VBA code and macros in the context of any Microsoft Office application are the same thing. Instead of referring to:
Quote:
the 'Split Merged Output to Separate Documents' macro in the Mailmerge Tips and Tricks thread
I could have referred to:
Quote:
the 'Split Merged Output to Separate Documents' VBA code in the Mailmerge Tips and Tricks thread
and it would have meant the same thing.

Whether you copy & paste the VBA code from the link I gave you (which doesn't require you to install anything) or you sit there and re-type it for yourself, you'll end up with the same thing. Regardless, the same VBA code demonstrates how you can retrieve content from a document to use in the naming of a part of that document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 04-13-2017, 02:16 AM
mihnea96 mihnea96 is offline Save each split document with name from inside that document Windows 7 32bit Save each split document with name from inside that document Office 2010 32bit
Novice
Save each split document with name from inside that document
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default

ok. got it. thanks a lot!
Reply With Quote
  #5  
Old 04-13-2017, 04:15 AM
mihnea96 mihnea96 is offline Save each split document with name from inside that document Windows 7 32bit Save each split document with name from inside that document Office 2010 32bit
Novice
Save each split document with name from inside that document
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default

Hi, again!
I've tried using the "Split Merged Output to Separate Documents" macro but it asks "How many Section breaks are there per record?", I write how many there are, press OK and nothing happens.
I realized I should use the bellow code as i can use a delimiter to separate the Q&As, but still, I cannot save the documents with the text from inside it as name and it also changes the format style of the question, which initially was Heading1.
Could you kindly help??
Thanks!

Sub SplitNotes(delim As String, strFilename As String)
Dim Doc As Document
Dim arrNotes
Dim i As Long
Dim X As Long
Dim Response As Integer
arrNotes = Split(ActiveDocument.Range, delim)
Response = MsgBox("This will split the document into " & UBound(arrNotes) + 1 & " sections.Do you wish to proceed?", 4)
If Response = 7 Then Exit Sub
For i = LBound(arrNotes) To UBound(arrNotes)
If Trim(arrNotes(i)) <> "" Then
X = X + 1
Set Doc = Documents.Add
Doc.Range = arrNotes(i)
Doc.SaveAs ThisDocument.Path & "\" & strFilename & Format(X, "000")
Doc.Close True
End If
Next i
End Sub
Sub test()
'delimiter & filename
SplitNotes "///", "Notes "
End Sub
Reply With Quote
Reply

Tags
vba microsoft word 2013



Similar Threads
Thread Thread Starter Forum Replies Last Post
Save each split document with name from inside that document Word VBA - Split Document By Headings - Save File Name As Heading Name jc491 Word VBA 7 01-21-2022 11:04 AM
Save each split document with name from inside that document split word document based on bookmarks with each new document title of the bookmark megatronixs Word VBA 9 09-05-2020 02:29 PM
Vba code to save document as pdf using document property text and rename folder. staicumihai Word VBA 1 12-21-2015 07:39 AM
How to save active document to SharePoint document library Rose roon Word VBA 9 09-22-2015 10:53 PM
Save each split document with name from inside that document How do I see one document map for each half of a split MS WORD 2010 document? quickwin Word 3 07-09-2013 10:20 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:08 PM.


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