Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-16-2022, 03:55 AM
Bikram Bikram is offline Checking whether the selected lies with in an equation field Windows 10 Checking whether the selected lies with in an equation field Office 2007
Advanced Beginner
Checking whether the selected lies with in an equation field
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Unhappy Checking whether the selected lies with in an equation field


Greetings, What should be used with
Code:
    If .inrange(wd???)= true
to test whether the selected range lies within equation field?
Reply With Quote
  #2  
Old 03-16-2022, 05:57 AM
gmayor's Avatar
gmayor gmayor is offline Checking whether the selected lies with in an equation field Windows 10 Checking whether the selected lies with in an equation field Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 03-18-2022, 03:51 AM
Bikram Bikram is offline Checking whether the selected lies with in an equation field Windows 10 Checking whether the selected lies with in an equation field Office 2007
Advanced Beginner
Checking whether the selected lies with in an equation field
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 03-18-2022, 04:33 PM
macropod's Avatar
macropod macropod is offline Checking whether the selected lies with in an equation field Windows 10 Checking whether the selected lies with in an equation field Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As Greg said:
Quote:
Your question is short on context
It's not clear whether you're referring to an EQ field or a formula field (or, potentially, another field embedded in one of those), or maybe even an Equation object.

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
You can use the function with code like:
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]
Reply With Quote
  #5  
Old 03-19-2022, 09:54 PM
Bikram Bikram is offline Checking whether the selected lies with in an equation field Windows 10 Checking whether the selected lies with in an equation field Office 2007
Advanced Beginner
Checking whether the selected lies with in an equation field
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default

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
Reply With Quote
Reply



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
Checking whether the selected lies with in an equation field 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
Checking whether the selected lies with in an equation field Word Equation field codes mkarthic Word 1 12-02-2011 02:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft