Consulting

Results 1 to 6 of 6

Thread: Find text and determine first character

  1. #1
    VBAX Newbie
    Joined
    Aug 2014
    Posts
    3
    Location

    Post Find text and determine first character

    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

  2. #2
    I have just answered this in the MSDN forum?
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Aug 2014
    Posts
    3
    Location
    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.

  4. #4
    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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Newbie
    Joined
    Aug 2014
    Posts
    3
    Location
    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

  6. #6
    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.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •