-
September 16th, 2014, 06:43 PM
#1
To get message box result as a string as one by one
Hi Guys,
The below code displays tab count of every paragraphs in msg box.
But I need paragraphs tab count as one by one as a string.
for example. First Para tab count as "10", second para tab count as "4", third para tab count as "8" etc.,
Output should be
10 (as string)
4 (as string)
8 (as string)
So that I will match that string and do some process.
Code:
Sub Demo()
Dim i As Long, StrRslt As String
StrRslt = "This document's paragraphs contain the following tab counts: " _
& vbCr & vbTab & "Paragraph" & vbTab & vbTab & "Tabs"
With ActiveDocument.Paragraphs
For i = 1 To .Count
StrRslt = StrRslt & vbCr & vbTab & i & vbTab & vbTab & UBound(Split(.Item(i).Range.Text, vbTab))
MsgBox StrRslt
Next
End With
End Sub
Thanks
-
September 18th, 2014, 10:41 PM
#2
Re: To get message box result as a string as one by one
I'm not sure I understand your question nor what you expect the output to be
What output are you getting now?
I am assuming that this is not VB code. Word VBA?
Always use [code][/code] tags when posting code.
-
September 19th, 2014, 11:45 AM
#3
Re: To get message box result as a string as one by one
Yes Datamiser,
Its a word vba code. Now I am getting the para number and tab count in the msg box. I want only the tab count as result.
What I am searching for is?
I have 2 codes, One is to get the tab count of the every paragraph (code in my previous post) And the Second is getting some numeric value from every paragraph from the below code.
I like to compare both the values, i.e., tab count and numeric value of each and every paragraph.
For example, If the tab count of the 1st para is 10 (1st code output "MsgBox StrRslt") and numeric value is 9 (2nd Code output " MsgBox newmd") that para should be highlighted.
If both are same should search for the next para, likewise throughout the document.
Inshort If StrRslt = newmd skip and goto next. If not equal Highlight the para
2nd Code for your reference
Code:
Public Sub Splitstring()
Dim strtxt As String
Dim strtmp As String
Dim md, b As String
Dim x As Integer
With ActiveDocument.range
' Loop through all paragraphs
For i = 1 To .Paragraphs.count
'Get the paragraph text, minus the paragraph marker
strtmp = .Paragraphs(i).range.Text
strtmp = Left(strtmp, Len(strtmp) - 1)
For j = 1 To UBound(split(strtmp, Chr(45)))
strtxt = split(strtmp, Chr(45))(j)
strtxt = Left(strtxt, 3)
md = strtxt
For x = 1 To Len(md)
L = Mid(md, x, 1)
If IsNumeric(L) Then newmd = newmd & L
Next x
MsgBox newmd
Application.ScreenUpdating = True
newmd = ""
Next
Next
End With
End Sub
1st code
Code:
Sub Demo()
Dim i As Long, StrRslt As String
StrRslt = "This document's paragraphs contain the following tab counts: " _
& vbCr & vbTab & "Paragraph" & vbTab & vbTab & "Tabs"
With ActiveDocument.Paragraphs
For i = 1 To .Count
StrRslt = StrRslt & vbCr & vbTab & i & vbTab & vbTab & UBound(Split(.Item(i).Range.Text, vbTab))
MsgBox StrRslt
Next
End With
End Sub
-
September 19th, 2014, 03:21 PM
#4
Re: To get message box result as a string as one by one
I don't do Word VBA so off the top of my head I have no idea how to highlight a paragraph in Word via VBA code
As for your question it sounds simple enough
In your second piece of code compare the strings and if they match then add the code to highlight and exit the For loop
Assuming of course I understand what you are trying to do
Always use [code][/code] tags when posting code.
-
September 20th, 2014, 04:52 PM
#5
Re: To get message box result as a string as one by one
What the problem is I can't able to get the Tab Count as Numeric String of 1st Code.
If I got the Numeric string, I will compare the strings and highlight the para through loop.
If anyone helps, it should be appreciated.
-
September 20th, 2014, 05:01 PM
#6
Re: To get message box result as a string as one by one
I'm not sure what you are talking about "numeric string"
If you want to work with numbers a string is not what you would use
Always use [code][/code] tags when posting code.
-
September 23rd, 2014, 07:24 PM
#7
Re: To get message box result as a string as one by one
Thanks for your kind response for all the post,
At last I made it through the below coding.
Code:
Public Sub Splitstring()
Dim strtxt As String
Dim strtmp As String
Dim i As Long
Dim md, b As String
Dim x As Integer
Dim k As Long, strrslt As String
With ActiveDocument.range
' Loop through all paragraphs
For i = 1 To .Paragraphs.count
'Get the paragraph text, minus the paragraph marker
strtmp = .Paragraphs(i).range.Text
strtmp = Left(strtmp, Len(strtmp) - 1)
For j = 1 To UBound(split(strtmp, Chr(45)))
strtxt = split(strtmp, Chr(45))(j)
strtxt = Left(strtxt, 3)
md = strtxt
For x = 1 To Len(md)
l = Mid(md, x, 1)
If IsNumeric(l) Then newmd = newmd & l
Next x
'MsgBox newmd
With ActiveDocument.Paragraphs
strrslt = UBound(split(.Item(i).range.Text, vbTab))
'MsgBox StrRslt
End With
'MsgBox "Numeric " & newmd & "TAB " & strrslt
If newmd = strrslt Then
ElseIf newmd = "" Then
Else
ActiveDocument.Paragraphs(i).range.Select
Options.DefaultHighlightColorIndex = wdYellow
Selection.range.HighlightColorIndex = wdYellow
End If
Application.ScreenUpdating = True
newmd = ""
Next
Next
End With
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|