Help with criteria search

A

Aaron

Hello,

I am taking raw output and formatting it to match our
proposals. I have it configured to add the borders,
graphic, headers, footers etc. via record macros.

I do not have issues with program flow, I am able to test
a character via if selection.text <> " " then msgbox kind
of thing and can get it to tell me true false.

What I don't know how to do is search each line at col
28, check for a value, if it has a value to move to the
begining of the line above, run a format macro, then
return to searching until it hits the end... Again at
the end I will need to test for a string to ensure that
it is the end, not just one char in that col.

if col28 <> " " and col 26 to 30 <> "five" then
call sub formatline()
else
next line
end if

That is the jist of what I am trying to do... any
pointers?

Thank you,

Aaron
 
H

Helmut Weber

Hi Aaron,
not too clear, what you mean,
in case you are talking of tables, a tables consists of
rows and columns that define cells. A cell may contain
more then one line (of text). Don't confuse rows with
lines. It makes help difficult.
If you need the text, which a cell contains,
you have to cut off 2 characters form the cell's range text,
because of the end-of-cell marker.
With ActiveDocument.Tables(1).Cell(1, 1)
MsgBox Left(.Range.Text, Len(.Range.Text) - 2)
End With
If you are using just selection, you have to move
the end of the selection 1 (!) character to the left:
With ActiveDocument.Tables(1).Cell(1, 1)
.Select
Selection.MoveEnd unit:=wdCharacter, Count:=-1
MsgBox Selection.Text
End With
If you select all of a cell
Selection.Text <> " " would be always true.
 
A

Aaron

Hi Helmut,

Thank you for the reply. Alas I am not dealing with
tables, however I will keep the response for future ref.

I am dealing with raw text and it seems that Word2000
would use a pointer to a specific location on the page
with something like page("Page#").line("Line#).column
("column#") much like Excel uses
Sheet("SheetName").Range("Range")

What I want to do is scan the raw text at location 28 of
each line. If location 28 on the line has a value, and
it does not match the end of the document string
criteria, I want to run a macro. If it is blank I want
it to go to the next line and continue to the end of the
product description section.

example-

1 mst3k/rsvp This is a show to watch $345.00 $345.00

vs.

1 mst3k/rsvp/dhcp This is a show that
asked for a channel $435.00 $435.00


notice that in the spot that was blank in example one,
right after mst3k/rsvp, there is now a value on the
second item and it is kicking out the description and
bumping the price to the next line... if the spot right
before the description has a value/is not blank I want to
run a macro to correctly format the botched up line....
see what I mean?

Aaron
 
H

Helmut Weber

Hi Aaron,
to the best of my knowledge, not a beginners task at all.
The following could work it's way through all the lines in a document,
and if the length of the line exceeds 40,
checks whether character(28) in the line = " ", and then
gets a 4 letter string beginning with character 26 in the line.
Depending on that, an action can be performed.
Lots of improvements possible.
HTH, though I have my doubts.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
---
Sub Makro7()
Dim iLn1 As Integer ' Line 1 of 2
Dim iLn2 As Integer ' Line 2 of 2

With ActiveWindow ' word bug workaround
.View = wdPrintView
.View = wdNormalView
.View = wdPrintView
End With
With Selection
.WholeStory
.Collapse
.ExtendMode = False
iLn1 = .Information(wdFirstCharacterLineNumber)
.Bookmarks("\line").Select
If Len(.Range.Text) > 40 Then
If .Range.Characters(28) = " " Then
.Range.Characters(26).Select
.MoveRight Count:=3, Extend:=wdExtend
MsgBox "! [" & .Range.Text & "]" ' for testing
' action depending on .Range.Text
End If
End If
.MoveDown
iLn2 = .Information(wdFirstCharacterLineNumber)
While iLn1 <> iLn2
.Bookmarks("\line").Select
If Len(.Range.Text) > 40 Then
If .Range.Characters(28) = " " Then
.Range.Characters(26).Select
.MoveRight Count:=3, Extend:=wdExtend
MsgBox "! [" & .Range.Text & "]" ' for testing
' action depending on .Range.Text
End If
End If
iLn1 = .Information(wdFirstCharacterLineNumber)
.MoveDown
iLn2 = .Information(wdFirstCharacterLineNumber)
Wend
End With
End Sub
 
A

Aaron

Hi Helmut,

Thank you very much! The code is helpfull. I made some
modifications as it was not stopping on the correct
lines, so the line = " " is changed to line <> " ".

Some issues I can not seem to figure out so far is what
the .bookmark("/line") is for and also how to get it to
start searching on a differant line vs. the first line.
I added watches to the bookmark and it does not seem to
have any value change. Genius on the iLN vars to move
through the document.

Any tips on how to start at certain lines and end at
others will be paramount and I believe I can finish it
from there as the object browser has not been very
helpfull.

Aaron
 
A

Aaron

Hi Helmut,

Thank you for the help here. I have the code and will
play with it for the day. May post again today or
tomorrow, either way I will be back.

Aaron
 

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