Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
342 Views, 2 Replies

Error in inserting Border into drawing through userform

Hello, still coming to grips with VBA, but managed to use the same code below to insert various title blocks through a userform. I have separated the code now to just generate on the click of a button to test out inserting a drawing border. I don't seem to be able to correct the errors in the code that are giving me a 'wrong number of arguments or invalid property assignment' while highlighting the oSheet.AddBorder at the end of the code. If anyone has any ideas how to fix I would highly appreciate this.

 

Sub GenerateButton_Click()
    
    'Get the active document.
    Dim oDrawDoc As Document
    Set oDrawDoc = ThisApplication.ActiveDocument

    'Get the PropertySets object.
    Dim oPropSets As PropertySets
    Set oPropSets = oDrawDoc.PropertySets
    
    ' Obtain a reference to the desired border defintion.
    Dim oBorderDef As BorderDefinition
    Set oBorderDef = oDrawDoc.BorderDefinitions.Item("Default Border")

    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet

    ' Check to see if the sheet already has a border and delete it if it does.
    If Not oSheet.Border Is Nothing Then
        oSheet.Border.Delete
    End If

    Dim sPromptStrings(1 To 2) As String
    sPromptStrings(1) = "String 1"
    sPromptStrings(2) = "String 2"

    ' Add an instance of the border definition to the sheet.
    Dim oBorder As Border
    Set oBorder = oSheet.AddBorder(oBorderDef, , sPromptStrings)
    
    Unload Me

End Sub