Word 2003 removed the save as "text with layout"
option which is what I used.
I am looking to take an RTF file from word and make a text file that has only spaces and CR/LF
BUT
I need to save the layout so an indented paragraph should have spaces added to the line so that it lines up like it used to.
I am so skeptical, I can hardly believe it!
PS I am not a 'hyperactive member' I am a cool, calm, and collected member
do you want to write code to do this or just a simple solution, which could be put into code anyway?
find all tabs and replace with spaces (however many spaces to make it look right). if you have tabs in other parts of your document it may give a problem, but that could filtered by sections
help, I am trying to work with paraformat2 and I am having a hard time.
here is the code I am dealing with.
Command1_Click() gets me the text just fine but it looses the indenting.
it looked like paraformat2 could query the line and tell me its indent.
with the text, and the indent I would be able to pad the front of the text with spaces.
can someone help me with the paraformat2 type declaration and how to use the EM_GETPARAFORMAT sendmessage?
thanks
VB Code:
Private Declare Function SendMessageAsLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessageAsString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_USER = &H400
Const EM_GETPARAFORMAT = (WM_USER + 61)
Const EM_SETPARAFORMAT = (WM_USER + 71)
Const MAX_TAB_STOPS = 32&
Const PFM_LINESPACING = &H100&
Const EM_GETLINE = &HC4
Const EM_GETLINECOUNT = 186&
Const EM_GETWORDBREAKPROC = &HD1
Const EM_LIMITTEXT = &HC5
Private Type PARAFORMAT2
cbSize As Integer
wPad1 As Integer
dwMask As Long
wNumbering As Integer
wReserved As Integer
dxStartIndent As Long
dxRightIndent As Long
dxOffset As Long
wAlignment As Integer
cTabCount As Integer
lTabStops(0 To MAX_TAB_STOPS - 1) As Long
dySpaceBefore As Long ' Vertical spacing before para
dySpaceAfter As Long ' Vertical spacing after para
dyLineSpacing As Long ' Line spacing depending on Rule
sStyle As Integer ' Style handle
bLineSpacingRule As Byte ' Rule for line spacing
bCRC As Byte ' Reserved for CRC for rapid searching
wShadingWeight As Integer ' Shading in hundredths of a per cent
maybe this api is not the way to go.
My real intent is to find out how a paragraph is indented so that I can add spaces to the text.
For those who PM me,
I can get the TEXT. My goal is getting it formatted with spaces and hard returns so it looks close to the original.
being one space off won't kill me, so if something is indented .2" and 4 spaces is a little short, that is OK, but I want to know if it is .2" or .4" of indent.. that is the real trick..
thanks
I am so skeptical, I can hardly believe it!
PS I am not a 'hyperactive member' I am a cool, calm, and collected member
left indent returned 18 on the first paragraphs of the sample file, i believe that is 18 points, ¼".
i was looking at that, but hadn't decided yet what could be done with it as the paragraph is a single line in the RTF file, before word wrapping
the line indent in the RTF code (/li360) varied a lot, but shows as 360 in many instances, which also converts to ¼"
you can read the RTF code for each paragraph, then apply that as you get each paragraph of text.
pete
edit: in vb you can use textwidth to make the number of spaces very accurate for the length of the gap you want to insert
VB Code:
strl = (leftindent) / TextWidth(" ")
mystr = Space(strl)
remember that the font face and size will change the textwidth, so set the font of the form or a picture box to the required font if it is not a same font, unless you are printing it direct, then use the printers textwidth
Last edited by westconn1; Jul 8th, 2006 at 03:01 AM.
here is code that reads your sample file and saves it as text file with spaces to format the document with indents.
so far i have not done anything to word wrap the longer lines of text, but that will not be too hard to do, just not tonight, try the code on seversl files, see how many bugs in it.
VB Code:
Private Sub Command1_Click()
Dim i As Integer, pos As Integer, mytest, pos1 As Integer
Dim li As Integer, strfi As String, f1 As Integer, arrfi() As String, pard As Boolean
Dim tlen As Integer, myind As String
f1 = FreeFile
Open "spec.rtf" For Input As f1
strfi = Input(LOF(f1), #f1)
Close f1
pard = False
arrfi = Split(strfi, vbNewLine)
Open "spec.txt" For Output As f1
For i = 0 To UBound(arrfi)
If pard = False Then
If InStr(1, arrfi(i), "\pard") = 0 Then
GoTo notyet
Else: pard = True
End If
End If
pos = InStr(1, arrfi(i), "\li")
If Not pos = 0 Then
pos1 = InStr(pos + 3, arrfi(i), "\") - pos - 3
mytest = Mid(arrfi(i), pos + 3, pos1)
If Left(mytest, 1) = "n" Then
pos = InStr(pos + 1, arrfi(i), "\li")
If Not pos = 0 Then
pos1 = InStr(pos + 3, arrfi(i), "\") - pos - 3
mytest = Mid(arrfi(i), pos + 3, pos1)
End If
End If
li = Val(mytest)
' Debug.Print li, i
End If
mytest = ""
tlen = li / 4 / TextWidth(" ")
myind = Space(tlen)
pos = InStrRev(arrfi(i), "\")
If pos = 0 Then
mytest = arrfi(i)
Else
pos = InStr(pos + 1, arrfi(i), " ")
If pos = 0 Then Stop
pos1 = Len(arrfi(i))
If Not Len(arrfi(i)) = pos Then mytest = Right(arrfi(i), Len(arrfi(i)) - pos)
End If
If mytest = "" Or mytest = "}}" Then mytest = " "
If Left(mytest, 1) = "{" Then mytest = Right(mytest, Len(mytest) - 1)
notyet:
If Not mytest = "" Then Print #f1, myind & mytest 'mytest = "not yet"
Fire Alarm Equipment Specifications
>080<
Manual Pull Station
box cover at 44" AFF.
>090<
15 Candela Fire Alarm Horn/Strobe
Simplex #4903-9428 Audible/Visible unit (15 Candela, 1 Hz flash rate, off-white w/Red
"FIRE"). Mount on recessed 4" square box with bottom of unit at 80" AFF.
>093<
110 Candela Fire Alarm Horn/Strobe
Simplex #4903-9430 Audible/Visible unit (110 Candela, 1 Hz flash rate, off-white w/Red
"FIRE"). Mount on recessed 4" square box with bottom of unit at 80" AFF.
>095<
Fire Alarm Horn only
Simplex #4901-9820 Horn with 4905-9989 cover (White).
Mount on recessed 4" square box with bottom of unit at 80" AFF.
>100<
15 Candela Fire Alarm Strobe only
Simplex #4904-9342 Visible Only Unit (15 Candela, 1 Hz flash rate, off-white w/Red
"FIRE"). Mount on recessed 4" square box with single gang plaster ring with bottom of
the unit at 80" AFF.
>105<
110 Candela Fire Alarm Strobe only
Simplex #4904-9344 Visible Only Unit (110 Candela, 1 Hz flash rate, off-white w/Red
"FIRE"). Mount on recessed 4" square box with single gang plaster ring with bottom of
the unit at 80" AFF.
>110<
Photoelectric Smoke Detector
Simplex #4098-9601 detector w/ #4098-9788 base, surface mount on suspended
ceiling on 4" octagonal box.
>120<
Photoelectric Duct Smoke Detector
Simplex #4098-9686 smoke/housing & appropriate sampling tube, mount w/ sampling
tube in air stream or air duct.
>130<
Photoelectric Smoke Detector w/ Aux. DPDT Relay Contacts
Simplex #4098-9601 detector w/ #4098-9682 base with relay, surface mount on
suspended ceiling on 4" octagonal box.
>140<
Heat Detector
Simplex #4098-9613 detector w/ #4098-9682 base rate of rise (15 degree F/min) and
fixed temperature (136 degree F) heat detector. Mount on recessed 4" octagonal box in
ceiling.
>150<
Fixed Temperature Heat Detector
Simplex #4098-9612 detector w/ #4098-9682 base 135 degree F fixed point detector
w/2 normally open contacts. Mount on 4" octagonal box.
>160<
Remote Test / Alarm Indicator Station
box cover at 54" AFF.
>170<
Smoke Damper
damper motor. Wired by EC.
>180<
Sprinkler Flow Switch
SPDT contacts provided by Sprinkler Contractor, wired by EC.
>190<
Sprinkler Tamper Switch
Switch w/normally closed contacts provided by Sprinkler Contractor, wired by EC.
>200<
Fire/Smoke Door
link (re-usable), wired by EC.
>210<
Fire Alarm Control & Annunciator Panel Specifications
>220<
Simplex #4004 series, 24V DC Fire Alarm with:
>230<
Simplex #4005 series, 24V DC Fire Alarm with:
>260<
4 hour battery
>270<
24 hour battery monitoring plus 5 minute alarm
>280<
Provision for 24VDC reverse polarity city fire dept. signal module
>285<
LED annunciator panel.
>290<
status command unit (SCU) remote annunciator panel.
>300<
Fire Alarm Zones
>310<
1st Floor
2nd Floor
3rd Floor
Sprinkler Flow Switches
Spare
Spare
Spare
Spare
>320<
Spare
Spare
Spare
Spare
Spare
Spare
Spare
Spare
>330<
Spare
Spare
Spare
Spare
Spare
Spare
Spare
Spare
>340<
Spare
Spare
Spare
Spare
Spare
Spare
Spare
Spare
>350<
See Details on Sheet E7
>000<
I am so skeptical, I can hardly believe it!
PS I am not a 'hyperactive member' I am a cool, calm, and collected member
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete