Splitting a Document

E

Edgar

Hi

The supplier reference will be a 6 digit number starting
with a 1. Let me know if you need any more info.

E
 
H

Helmut Weber

Hi Edgar,
in principle you have to search the doc for the
seperator, the 6 digit number, create a new document,
set it's range for the range, that your search procedure defines,
save it with a name, defined by the 6 digit number,
cut off the range, that the search procedure defined, etc.
Which is highly imperfect, but could be a start.
Not quite simple, though. Some questions still remain.
Sub Makro2()
Dim d1 As Document
Dim d2 As Document
Dim r1 As Range
Dim r2 As Range
Dim s As String
Set d1 = ActiveDocument
Set r1 = d1.Range
With r1.Find
.Text = "1[0-9]{5}"
.MatchWildcards = True
.Execute
If .Found Then
s = r1.Text
r1.Start = 0
Set d2 = Documents.Add()
Set r2 = d2.Range
r2 = r1
r1.Delete
d2.SaveAs "c:\test\" & s & ".doc"
End If
End With
End Sub




Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word XP, Win 98
 
B

Bruce Brown

Edgar

This is kind of a crude one. It searches for any six digit number
starting with 1 and puts in a section break before it. Then it goes
back to each supplier reference number and selects the entire section
to be e-mailed.

Doug will probably have something more operationally efficient, but
maybe this can serve as a small primer on ranges and how to find text
with them. - Bruce

Sub SupplierRefSections ()
Dim R As Range, Sec As Section, Cnt As Long
Set R = ActiveDocument.Range
With R.Find
.Text = "1^#^#^#^#^#"
Do While .Execute
R.InsertBreak Type:=wdSectionBreakNextPage
R.MoveEndWhile "1234567890"
R.Font.Color = wdColorRed
R.Font.Bold = True
Cnt = Cnt + 1
ActiveDocument.Bookmarks.Add Range:=R, Name:="SupplierRef" &
Cnt
Do While R.Information(wdWithInTable) = True
R.MoveEnd wdParagraph
Loop
R.Collapse wdCollapseEnd
Loop
End With
For Cnt = 1 To Cnt
Selection.GoTo What:=wdGoToBookmark, Name:="SupplierRef" & Cnt
MsgBox "Supplier Ref No"
Selection.Sections(1).Range.Select
MsgBox "Section to be e-mailed to supplier"
Next
End Sub
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Edgar,

If you run a macro containing the following code when the document is
active, it will save each portion as a separate document with the filename
being the supplier reference:

Dim Source As Document, Target As Document, arange As Range, fname As
String
Set Source = ActiveDocument
Selection.EndKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="1[0-9]{5}", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=False) = True
Set arange = Selection.Range
fname = arange.Text
arange.End = Source.Range.End
Set Target = Documents.Add
Target.Range = arange
arange.Delete
Target.SaveAs fname
Target.Close
Loop
End With


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Bruce,

See my response to Edgar. This is a case where it is easiest to start at
the end of the document and work forward as then all you have to do is find
the start of each section.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
B

Bruce Brown

Doug,

Agree that it makes better sense to search backwards.

Curious, though - is there some reason you prefer selection find over
range find in this case, since either can be used? - Bruce


Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS said:
Hi Edgar,

If you run a macro containing the following code when the document is
active, it will save each portion as a separate document with the filename
being the supplier reference:

Dim Source As Document, Target As Document, arange As Range, fname As
String
Set Source = ActiveDocument
Selection.EndKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="1[0-9]{5}", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=False) = True
Set arange = Selection.Range
fname = arange.Text
arange.End = Source.Range.End
Set Target = Documents.Add
Target.Range = arange
arange.Delete
Target.SaveAs fname
Target.Close
Loop
End With


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
Edgar said:
Hi

The supplier reference will be a 6 digit number starting
with a 1. Let me know if you need any more info.

E
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Bruce,

There is no reason that I used Selection instead of Range other than that
was what was used by the macro that I modified for this purpose.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
Bruce Brown said:
Doug,

Agree that it makes better sense to search backwards.

Curious, though - is there some reason you prefer selection find over
range find in this case, since either can be used? - Bruce


"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
Hi Edgar,

If you run a macro containing the following code when the document is
active, it will save each portion as a separate document with the
filename
being the supplier reference:

Dim Source As Document, Target As Document, arange As Range, fname As
String
Set Source = ActiveDocument
Selection.EndKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="1[0-9]{5}", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=False) = True
Set arange = Selection.Range
fname = arange.Text
arange.End = Source.Range.End
Set Target = Documents.Add
Target.Range = arange
arange.Delete
Target.SaveAs fname
Target.Close
Loop
End With


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
Edgar said:
Hi

The supplier reference will be a 6 digit number starting
with a 1. Let me know if you need any more info.

E


-----Original Message-----
Edgar,

Give us some more information about how the supplier reference can be
identified.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
Hi

Not sure if this is possible but i have a large document
that is generated from Crystal Reports and is saved in rtf
format.

This report is lots of different remittances for suppliers
but we cannot split this up to individual suppliers from
Crystal so at the moment we are forced to email page
ranges which is very time consuming.

The problem is the remittances range from 1 page to 15
pages so i would need to set up some kind of loop to check
the supplier reference and then for it to save as the
supplier reference.

The supplier reference is always in the same place on the
document so is it possible to set a marker on this to be
used in a loop. Sorry but i know next to nothing about
word vba. Thanks in advance for your help.

Edgar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top