Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word VBA help needed

Status
Not open for further replies.

Terradive

Programmer
Aug 8, 2013
1
US
I need to split a RTF document based on a delimiter which is done. But it is not dragging over the formatting. I would like to keep my bold fonts and tab spacing. It is currently recording a tab as 5 spaces when in the original document it can be 40 spaces. I'm also not sure the page. Setup will be necessary after a solution is found. Any help would be appreciated. Code below.

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
'Dim arrNotes As Document
arrNotes = Split(ActiveDocument.Range.FormattedText, 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

Dim wd As Word.Application
Set wd = Application

Set doc = wd.Documents.Add

'doc.Range = arrNotes(I)
billz.Range.FormattedText = arrNotes(I)

Dim ZA As Double
ZA = Left(arrNotes(I), 9)
With doc.PageSetup

.Orientation = wdOrientLandscape
.BottomMargin = InchesToPoints(0.17)
.TopMargin = InchesToPoints(0.17)
.LeftMargin = InchesToPoints(0.25)
.RightMargin = InchesToPoints(0.25)
.VerticalAlignment = wdAlignVerticalTop
End With
doc.SaveAs ThisDocument.Path & "\" & ZA & ".doc", (wdFormatOriginalFormatting)

doc.Close True
End If
Next I
End Sub
Sub test()
'delimiter & filename
SplitNotes "EndEntry", "EndEntry"
End Sub
 
hi,
It is currently recording a tab as 5 spaces when in the original document it can be 40 spaces.

My guess is that your original doc had some TAB definition for the text range in question and the new doc does not have that same TAB definition. Change the TAB definition and you get your "40 spaces" I'm not certain that the new foc inherits all the formatting. Just a guess.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top