PDA

View Full Version : Find text and determine first character



Piri10
08-21-2014, 01:09 AM
I have to search for a code that has 3 characters - 7 characters - 2 characters - 1 characters and always starts with 0REG
The characters of the code can be 0-9 and A-Z
e.g. 0REG123-1TR456A-D2-5
What should I put where the ??? are?
Sub Registratiecode()
Dim oRng As Range
Set oRng = ActiveDocument.Sections(1).Range
With oRng.Find
Do While .Execute(FindText:="0REG ???", MatchWildcards:=True)
Select Case oRng.Characters(1)
Case 0: Call MacroRegCode
Case Else
End Select
Exit Do
Loop
End With
End Sub

gmayor
08-21-2014, 06:24 AM
I have just answered this in the MSDN forum?

Piri10
08-21-2014, 11:49 PM
Yes Graham, thanks for that.
This was for a slightly different problem because in an other document the codes
didn't have letters and numbers on specific places but could be everywhere.

gmayor
08-22-2014, 12:37 AM
The macro looks the same, and my response would also be the same

Sub Registratiecode()
Dim oRng As Range
Dim strFind As String
strFind = "0REG[A-Z0-9]{3}-[A-Z0-9]{7}-[A-Z0-9]{2}-[A-Z0-9]"
Set oRng = ActiveDocument.Sections(1).Range
With oRng.Find
Do While .Execute(FindText:=strFind, MatchWildcards:=True)
Call MacroRegCode
Exit Do
Loop
End With
End Sub

Piri10
08-22-2014, 12:44 AM
Didn't know it was that easy, I used [0-9,A-Z] which didn't work.
Didn't think about the fact that the comma wasn't needed there.


Would you know how I can change the code below so that only comments of one specific author are deleted?

Sub DeleteComments()
Dim cm As Comment
For Each cm In ActiveDocument.Comments
cm.Delete
Next
End Sub

gmayor
08-22-2014, 12:58 AM
Again, I just answered in the other forum.
To avoid unnecessary duplication of effort, please don't ask the same question in multiple forums without cross referencing them.