Working with Text that needs Word VBA functionality

C

Chuck

Here's what I am trying to accomplish to manipulate a
text file. I have a template that opens a Test.txt file
in the same directory and initializes a form that is used
for find / replace functionality. I use the following
code to find a string that exist 4x in Test.txt:
--------------------------------------
Set myRange = ActiveDocument.Range(Start:=0, End:=99)
strtest = ActiveDocument.Range(Start:=0, End:=0)
strtest = Right(myRange, 9)
txtfind.Value = strtest
--------------------------------------------
The above sets the find on the form.
The below code sets the replace on the form:
--------------------------------------------
Dim Order As Variant

txtreplace.Value = System.PrivateProfileString
("C:\Text\Autonumber.Txt", _
"MacroSettings", "Order")

If Order = "" Then
Order = 301000
Else
Order = Order + 1
End If
---------------------------------------------
My cmdclick runs the find replace code, increments the
autonumber in the Autonumber.txt file, and closes the
form. Up to this point, everthing is working as
desired. The problem I am running into is during the
save as Test1.txt. Word is formatting spaces at the end
of Test1.txt, which are not desirable. Any suggestions
would be greatly appreciated.
Thanks,
 
H

Helmut Weber

Hi Chuck,
Word is formatting spaces at the end of Test1.txt
Forgive me, but what would that mean?
Bold, italic, underlined spaces?
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word XP, NT 4.0
 
C

Chuck

Helmut, thank you for your response. I should have done a
better job explaining the problem. It adds a blank line
to the end of the text. Good Morning from Greenville,
North Carolina.
Chuck
 
H

Helmut Weber

Hi Chuck,
as the last paragraph-mark cannot be replaced, AFAIK,
some procedures doing a search and replace including
a paragraph mark add in fact one at the doc's end.
Have a look at this one:
Public Sub PurgeDocEnd()
Dim z As Long
Dim r As Range
With ActiveDocument
z = .Range.End
Set r = .Range(z - 2, z - 1)
While r.Text = " " Or r.Text = Chr$(13)
r.Delete
z = .Range.End
Set r = .Range(z - 2, z - 1)
Wend
End With
End Sub
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word XP, NT 4.0
 

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