#1
|
|||
|
|||
Checking whether the selected lies with in an equation field
Greetings, What should be used with Code:
If .inrange(wd???)= true |
#2
|
||||
|
||||
Your question is short on context, but maybe
Code:
Function InField(sText As String) As Boolean If Selection.Fields.Count > 0 Then If Selection.Fields(1).Type = wdFieldFormula Then If InStr(1, Selection.Fields(1).Code, sText) > 1 Then InField = True End If End If End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Sorry for late respond. I am very thankful for your reply. But it doesn't seems to work correctly. Even the stext(selection.text) is within the field it is not turning true.
|
#4
|
||||
|
||||
As Greg said:
Quote:
The following function determines whether the selection spans or is within a field of any kind. Code:
Function WithInField(Rng As Word.Range) As Boolean ' Based on code by Don Wells: http://www.eileenslounge.com/viewtopic.php?f=30&t=6622 ' Approach : This procedure is based on the observation that, irrespective of _ a field's ShowCodes state, toggling the field's ShowCodes state _ twice collapses the selection to the start of the field. Dim lngPosStart As Long, lngPosEnd As Long, StrNot As String WithInField = True: lngPosStart = Rng.Start: lngPosEnd = Rng.End With Selection .Fields.ToggleShowCodes .Fields.ToggleShowCodes ' Test whether the selection has moved; if not, it may already have been _ at the start of a field, in which case, move right and test again. If .Start = lngPosStart Then .MoveRight .Fields.ToggleShowCodes .Fields.ToggleShowCodes If .Start = lngPosStart + 1 Then WithInField = False End If End If End With End Function Code:
Sub TestWithInField() Application.ScreenUpdating = False Dim Rng As Word.Range, c As Word.Range, StrRslt As String Set Rng = Selection.Range For Each c In Rng.Characters StrRslt = StrRslt & c.Text & ",WithInField:" & WithInField(Rng:=c) & vbCr Next Rng.Select Application.ScreenUpdating = True MsgBox StrRslt End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
I am very grateful for your reply, Paul. I am sorry that I failed to describe in detail the question or problem. I was trying to insert commas inside numerical figures and trying to code like if the numerical text lies within field {(eq /f(2150,2204)} then ignore the comma.
Again, I want to thank you for your effort. Your code flags every character as True whether it is inside the field or not. However, I found a way to get my work done but it may be lengthy and error prone. Code:
If .Range.Characters(1).Previous.Text = "." Or .Range.Characters(1).Previous.Text = "," Or .Range.Characters(1).Previous.Previous.Text = "‚" Then rng.Fields.ToggleShowCodes Selection.MoveRight wdWord, 1, wdExtend If Selection.Range.Fields.Count = 1 Then ' I used this approach, it is manual but get the jobs done rng.Fields.ToggleShowCodes rng.Select GoTo exx Else rng.HighlightColorIndex = wdRed Selection.MoveRight wdCharacter, 1 End If |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Activate (show) a Drop-down form field when another drop-down form field is selected from | Jentis | Word VBA | 1 | 04-19-2018 09:42 PM |
Need a VBA func. that tells if a point lies above/below 3D polygon surface | gonurvia | Excel Programming | 0 | 03-29-2017 01:40 AM |
Get Name of Selected/Active Form Field | NumberCruncher | Word VBA | 8 | 01-20-2014 11:36 PM |
Insert an image that lies in two rows | raistlin | Word | 1 | 03-10-2013 02:11 PM |
Word Equation field codes | mkarthic | Word | 1 | 12-02-2011 02:09 AM |