Removing part of a string

Hello there,

Code is in corelx6

I'm still new to Corel VBA and have run into a wall with one of my macros. Turns out I don't understand strings very well and definitely don't understand how to modify them in VBA. 

Here's what I'm trying to do: Add the filename to a file but remove the extension from the end of the string.

Sub docunamerAP()

    Dim shArtistic As Shape
    Dim Doc As Document
    
    Set Doc = ActiveDocument
    
    'Creates doc name, uses Doc.Name property to insert document name
    Set shArtistic = Doc.ActivePage.ActiveLayer.CreateArtisticText(1.68522, 8.12906, Doc.Name, Font:="Arial", Size:=12, Bold:=cdrTrue)
        shArtistic.LeftX = 1.70033
        shArtistic.Fill.UniformColor.CMYKAssign 0, 0, 0, 100
        shArtistic.text.Story.ChangeCase (cdrTextUpperCase)
       ' modify string here ?
    
    Set shArtistic = Nothing
    Set Doc = Nothing

End Sub

Would someone be able to explain this process to me?

Thank you in advance!

  • VBA has a number of string handling functions that you could use to accomplish this. You can read about them on-line in a number of places.

    If you wished to simply lose the last four characters from the string, then here's one way to do that using Len and Left, then show the result in a message box.

    Sub drop_last_four_characters()
    Dim foo As String
    foo = ActiveDocument.Name
    foo = Left(foo, Len(foo) - 4)
    MsgBox foo
    End Sub

    Len is returning the length of the string.

    Left is returning the specified number of characters of the string, starting from the left. In this case, the specified number of characters is the original length minus 4.