- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
According to the help page the AddBorder() function takes 2 arguments.
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.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@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