PDA

View Full Version : Cutting text problem



vagabound_s
02-19-2009, 05:24 AM
Hi,

I am trying to create a program using VBA for word 2003 which will find all contents which go beyound the page boundry and thus are not visible. The program will store the references to those pragraphs in a listbox object.

After running the program the user will click the listbox items and the click event should take it to the respective location.

To acheive this I have created a procedure which will look for custom tabstops which go beyound page boundary or any fix static value, which will store the tabstop values in the list box.
Probelm 1: is there a better way to search for contents going beyond page width?

Problem 2: Though I am able to store the custom tab stops in the list, however the click even only selects tabstops within the page margins properly and for the tabstops beyong page margin it selects entire document. Please see below for the code.


'*********Code for finding custom tab stops
Sub findTabStop()
Dim i As Long
Dim Pmargin As Single
Dim CURRENT_DOCUMENT
Dim FFlag As Boolean
Dim Apara As Paragraph
Dim ATabstop As tabstop
FFlag = False
i = 1
Set CURRENT_DOCUMENT = ActiveDocument
Pmargin = ActiveDocument.PageSetup.RightMargin

For Each Apara In CURRENT_DOCUMENT.Paragraphs()
For Each ATabstop In Apara.TabStops
If ATabstop.CustomTab = True Then
'****check if the tab position greater than the page width
If ATabstop.Position > InchesToPoints(8) Then
FFlag = True
'****add tabstop values to listbox object in an form
UserForm1.TabList.AddItem PointsToInches(ATabstop.Position)
End If
End If
DoEvents
Next
Next
If FFlag = True Then
UserForm1.TabList.Visible = True
UserForm1.TabList.Enabled = True
End If
UserForm1.Show
End Sub

'*********Click even ot list box object:

Private Sub TabList_Click()
With ActiveDocument.Content.Find
.ClearFormatting
.Forward = True
.Format = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.ParagraphFormat.TabStops.Add Position:=InchesToPoints(UserForm1.TabList.Value)
.Text = ""
.Execute
.Parent.Select
End With
End Sub


Regards,
Harish

~Code Tags Added By Oorang
.