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

Error in inserting Border into drawing through userform

Anonymous

Error in inserting Border into drawing through userform

Anonymous
Not applicable

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
0 Likes
Reply
Accepted solutions (1)
343 Views
2 Replies
Replies (2)

JelteDeJong
Mentor
Mentor
Accepted solution

According to the help page the AddBorder() function takes 2 arguments.

JelteDeJong_0-1623842995468.png

In your code i see 3:

                                   1      2        3
Set oBorder = oSheet.AddBorder(oBorderDef, , sPromptStrings)

you could try:

Set oBorder = oSheet.AddBorder(oBorderDef, sPromptStrings)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Anonymous
Not applicable

@JelteDeJong  Fantastic, that was it! Thank you very much for your quick response. Good reminder to also consult the help page thoroughly. Have marked it as solution accepted.

 

Kind Regards, 

Joao

0 Likes