PDA

View Full Version : [SLEEPER:] Current line number & first letter of string is first letter of the line



nkpan
06-01-2018, 01:57 AM
Hello all,

I am working on a excel macro where a word file is opened and a list of string are searched.

I want to check if the string being searched is positioned at the start of a line. But i don't want the system to use cursor or selection, a simple find and execute and to check if the first character of the selected string is the first character of the line.

Any help would be greatly appreciated.

Hightree
06-01-2018, 03:41 AM
Perhaps you can show us a example?

Aussiebear
01-26-2025, 07:50 PM
Maybe try this code



Function IsAtStartOfSentence(ByVal SearchString As String, ByVal SearchRange As Range) As Boolean
' Declare variables
Dim StartOfSentence As String
Dim FoundPosition As Long
' Define the characters that can precede the start of a sentence
StartOfSentence = ".!?;"
' Add any other characters you consider as sentence endings
' Find the position of the search string within the specified range
FoundPosition = InStr(SearchRange.Text, SearchString)
' If the search string is not found, return False
If FoundPosition = 0 Then
IsAtStartOfSentence = False
Exit Function
End If
' Check if the character preceding the search string is a sentence ending character
If FoundPosition > 1 Then
If InStr(StartOfSentence, Mid(SearchRange.Text, FoundPosition - 1, 1)) > 0 Then
IsAtStartOfSentence = True
Else
IsAtStartOfSentence = False
End If
Else
' If the search string is at the very beginning of the range, assume it's at the start of a sentence
IsAtStartOfSentence = True
End If
End Function