Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-19-2021, 09:03 PM
yacov yacov is offline Selection between dots Windows 10 Selection between dots Office 2016
Competent Performer
Selection between dots
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default Selection between dots

Hi
Is there a command in VBA to select text that is between two points?
I would like to add this to an existing macro.


thanks,
Yacov
Attached Images
File Type: jpg SELECT TEXT.jpg (9.9 KB, 15 views)
Reply With Quote
  #2  
Old 07-19-2021, 10:36 PM
Guessed's Avatar
Guessed Guessed is offline Selection between dots Windows 10 Selection between dots Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You might need to explain why you need this and what the code is needing it for. You can search for content between two characters or you can find a sentence.

For instance to select the first sentence where the cursor is located
Selection.Range.Sentences(1).Select
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 07-19-2021, 11:05 PM
yacov yacov is offline Selection between dots Windows 10 Selection between dots Office 2016
Competent Performer
Selection between dots
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

Thanks, I made another macro version

Sub MyCalculatorSentences()
Selection.Range.Sentences(1).Select
Dim aChar As Variant, aRng As Range, iTotal As Long
Set aRng = Selection.Range
For Each aChar In aRng.Characters
Select Case AscW(aChar)
Case 1488 To 1497: iTotal = iTotal + AscW(aChar) - 1487
Case 1498: iTotal = iTotal + 20
Case 1499: iTotal = iTotal + 20
Case 1500: iTotal = iTotal + 30
Case 1501: iTotal = iTotal + 40
Case 1502: iTotal = iTotal + 40
Case 1503: iTotal = iTotal + 50
Case 1504: iTotal = iTotal + 50
Case 1505: iTotal = iTotal + 60
Case 1506: iTotal = iTotal + 70
Case 1507: iTotal = iTotal + 80
Case 1508: iTotal = iTotal + 80
Case 1509: iTotal = iTotal + 90
Case 1510: iTotal = iTotal + 90
Case 1511: iTotal = iTotal + 100
Case 1512: iTotal = iTotal + 200
Case 1513: iTotal = iTotal + 300
Case 1514: iTotal = iTotal + 400
Case 45: iTotal = iTotal * -1 'a minus sign
End Select
Next aChar
MsgBox iTotal
End Sub
Reply With Quote
  #4  
Old 07-27-2021, 02:27 AM
yacov yacov is offline Selection between dots Windows 10 Selection between dots Office 2016
Competent Performer
Selection between dots
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

Hi Andrew,
I have only one last problem, regarding the macro MyCalculator. In some of the paragraphs I used the sign / to indicate or.
That is:
A/B-C=D and this means that A=B and therefore should be ignored B.
Is there any line that can be added to the macro in order to draw such a version?
Attached Files
File Type: docx EXAMPLE.docx (12.0 KB, 5 views)
Reply With Quote
  #5  
Old 07-27-2021, 03:46 PM
Guessed's Avatar
Guessed Guessed is offline Selection between dots Windows 10 Selection between dots Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The easiest way would be to set the counter to zero if we encounter the / character. Effectively this is discarding A and starting counting again.
Code:
Sub MyCalculatorSentences()
  Selection.Range.Sentences(1).Select
  Dim aChar As Variant, aRng As Range, iTotal As Long
  Set aRng = Selection.Range
  For Each aChar In aRng.Characters
    Select Case AscW(aChar)
      Case 1488 To 1497: iTotal = iTotal + AscW(aChar) - 1487
      Case 1498: iTotal = iTotal + 20
      Case 1499: iTotal = iTotal + 20
      Case 1500: iTotal = iTotal + 30
      Case 1501: iTotal = iTotal + 40
      Case 1502: iTotal = iTotal + 40
      Case 1503: iTotal = iTotal + 50
      Case 1504: iTotal = iTotal + 50
      Case 1505: iTotal = iTotal + 60
      Case 1506: iTotal = iTotal + 70
      Case 1507: iTotal = iTotal + 80
      Case 1508: iTotal = iTotal + 80
      Case 1509: iTotal = iTotal + 90
      Case 1510: iTotal = iTotal + 90
      Case 1511: iTotal = iTotal + 100
      Case 1512: iTotal = iTotal + 200
      Case 1513: iTotal = iTotal + 300
      Case 1514: iTotal = iTotal + 400
      Case 45: iTotal = iTotal * -1 'a minus sign
      Case 47: iTotal = 0   'reset counter to zero if / encountered
      Case Else: Debug.Print AscW(aChar)    'show unhandled characters in Immediate Window
    End Select
  Next aChar
  MsgBox iTotal
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #6  
Old 07-27-2021, 10:01 PM
yacov yacov is offline Selection between dots Windows 10 Selection between dots Office 2016
Competent Performer
Selection between dots
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

thanks,
works great when a/b-c=d

is there a solution if / character come at the end, like: c-a/b=e
Reply With Quote
  #7  
Old 07-27-2021, 11:50 PM
Guessed's Avatar
Guessed Guessed is offline Selection between dots Windows 10 Selection between dots Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Well the obvious way would be to not include b in the selection since this code starts with the selection. The inclusion of the 'select the sentence' line is not such a good idea now that this '/' comes in to play in different positions. If the code just worked with what you selected then we wouldn't need to engineer special solutions to deal with increasingly complex cases.

The previous thread's code solution which processes all paragraphs wouldn't have the benefit of your fiddling the selection. That code could use a different approach by working out whether we have hit the '/' before or after a '-". However, since this code is working with Selection then it is far easier to simply not select the piece you want to ignore.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #8  
Old 07-28-2021, 12:17 AM
yacov yacov is offline Selection between dots Windows 10 Selection between dots Office 2016
Competent Performer
Selection between dots
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

Thank you,
I solved this in a simple way. I replaced the / with a paragraph mark. It left me with clean equations.
Reply With Quote
  #9  
Old 07-28-2021, 12:20 AM
Guessed's Avatar
Guessed Guessed is offline Selection between dots Windows 10 Selection between dots Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Simple solutions are almost always best
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Selection between dots Dots below tabs. slaycock Word 3 12-12-2017 06:12 AM
Dots in the margin salival0 Word 1 01-23-2017 10:20 PM
Selection between dots Selection of all Text for a specific page in word is spanning selection across pages ramsgarla Word VBA 9 12-05-2012 03:23 AM
Selection between dots Dots appear when typing mcs Word 1 11-21-2011 10:04 AM
dots musicman91 Word 1 11-02-2008 11:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:51 PM.


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