Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Removing Period from filename macro (Word 97 SR2)

    I have been unable to find a macro command to remove the period in a filename. For example, if the file name is "test123.doc" I would like to remove the period making it "test123doc."

    Help! <img src=/S/doh.gif border=0 alt=doh width=15 height=15>


    Thanks
    --Maria

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Removing Period from filename macro (Word 97 SR2)

    Maria,

    Here's one way to do it:

    <pre>Public Function strFileNameMinusPeriod(strFileName As String) As String
    'Note: Returns an empty string if there is no period in the filename
    Dim lngStrLen As Long
    Dim lngPdPos As Long
    Dim strL As String
    Dim strR As String

    lngStrLen = Len(strFileName)
    lngPdPos = InStr(strFileName, ".")

    If lngPdPos <> 0 Then
    strL = Mid$(strFileName, 1, lngPdPos - 1)
    strR = Mid$(strFileName, lngPdPos + 1, lngStrLen - lngPdPos)
    End If

    strFileNameMinusPeriod = strL & strR

    End Function
    '========================
    Public Sub Test()
    MsgBox strFileNameMinusPeriod("test123.doc")
    'MsgBox strFileNameMinusPeriod("test123doc")
    'MsgBox strFileNameMinusPeriod("test1.html")
    End Sub
    </pre>

    Gary

  3. #3
    3 Star Lounger siflaar's Avatar
    Join Date
    Jan 2001
    Location
    Amersfoort, Netherlands
    Posts
    203
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Removing Period from filename macro (Word 97 SR2)

    Maria,

    Why would you like to remove this period?
    Greetings,

    Patrick Schouten
    (The Netherlands)

  4. #4
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Removing Period from filename macro (Word 97 SR2)

    Hi Gary:

    Thank you very much for the sample code. One more question though. What if the filename have more than 1 period? The codes only remove the first one.

    Thanks
    --Maria

  5. #5
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Removing Period from filename macro (Word 97 SR2)

    Hi Patrick:

    We are using the filename to create a bookmark. Bookmarks doesn't accept periods.

    Thanks,
    --Maria

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Removing Period from filename macro (Word 97 SR2)

    It takes a few steps to make Gary's function remove all the periods, but here's how:
    <pre>Public Function strFileNameMinusPeriods(strFileName As String) As String
    Dim lngStrLen As Long
    Dim lngPdPos As Long
    Dim strL As String
    Dim strR As String

    'return original string if there is no period in the filename
    strFileNameMinusPeriods = strFileName

    'loop through and eliminate all periods
    While InStr(1, strFileNameMinusPeriods, ".") > 0
    lngStrLen = Len(strFileNameMinusPeriods)
    lngPdPos = InStr(strFileNameMinusPeriods, ".")
    strL = Mid$(strFileNameMinusPeriods, 1, lngPdPos - 1)
    strR = Mid$(strFileNameMinusPeriods, lngPdPos + 1, lngStrLen - lngPdPos)
    strFileNameMinusPeriods = strL & strR
    Wend
    End Function

    '========================
    Public Sub Test()
    MsgBox strFileNameMinusPeriods("test123.doc")
    MsgBox strFileNameMinusPeriods("test123doc")
    MsgBox strFileNameMinusPeriods("my.oddly.named.doc")
    End Sub</pre>


  7. #7
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Removing Period from filename macro (Word 97 SR2)

    Jeff and to all!

    Thanks so much! Works like a charm.

    I love this newsgroup!

    Thanks again
    --Maria

Posting Permissions

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