Any way to put a page break into a string?

E

Ed

I'm parsing a huge text file into several smaller files. I capture
the portion I want to make into a new file in a string, open a
TextStream object, and write the string plus a bit more. (Code is
below.) At certain points in the new file, I would like to insert a
page break. I'm thinking I would have to use something like InStr to
find the bit that marks a new page, then insert the break into the
string at that point. But can you do that in a string? Or is there
another way to put a page break in a TextStream file?

Ed

Set docNew = fs.CreateTextFile(strNewDoc)
docNew.Write (strNew & vbCr & vbCr & _
"This file created from archive files on " & _
Format(Now, "dd mmm yyyy"))
 
H

Helmut Weber

Hi Ed,

try putting a chr(12) it the string.

But there is more to it.

See: http://tinyurl.com/244hwp

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
E

Ed

Hi, Helmut.

Hi Ed,

try putting a chr(12) it the string.

But there is more to it.

But only if I want something other than a plain page break?

I do not want a section brealk, just a page break. So I can use
Replace(strDocText, strBreakText, strBreakText & Chr(12),
1,-1,vbTextCompare) ???

Ed
 
H

Helmut Weber

Hi Ed,

But only if I want something other than a plain page break?

yes, seems so.

Tested with:

Sub Macro4()
ActiveDocument.Range.Text = _
String(100, "x") & Chr(12) & String(100, "y")
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

Klaus Linke

It might work well, but I feel a bit queasy about it.
Especially since ^12 doubles as page break and section break.

Maybe better to make a more elaborate macro using
..InsertBreak(Type:=wdPageBreak) between the individual strings ...

Regards,
Klaus
 
H

Helmut Weber

Hi Klaus,
It might work well, but I feel a bit queasy about it.
Especially since ^12 doubles as page break and section break.

indeed, though after executing

ActiveDocument.Range.Text = _
String(100, "x") & Chr(12) & String(100, "y")

there is no section break to be found.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

Klaus Linke

You're probably right. I have frequently inserted text containing ^13 for
paragraph marks myself (even though I know better than to insert ^13 with a
Find/Replace), and never saw problems.

:) Klaus
 

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