vbaexcelpropertiesinline-code

VBA set "PrintObject" property false, inlinecode


I created a ActiveX Button in my SourceCode and locade it. After that I changed the Caption protery and get it an click event. Now I have to change the "Print Object" property inside my Source Code.

But I don´t know how.

I tried that one:

ActiveSheet.OLEObjects((22 + counter)).Object.PrintObject= False

(22 is the index from the Button)

and

Dim rangeString As range
Dim name As String
name = "J" & verifyRow & ":" & "K" & verifyRow
Set rangeString = ActiveSheet.range(name)
Set obj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False, DisplayAsIcon:=False, Left:=rangeString.Left, Top:=rangeString.Top, Width:=rangeString.Width, Height:=rangeString.Height, PrintObject:=False)

But nothing works.


Solution

  • You can use

    ActiveSheet.OLEObjects("CommandButton1").PrintObject = False
    

    where CommandButton1 is the name (not the caption) of your button.

    Or if you like to use indices

    ActiveSheet.OLEObjects(1).PrintObject = False
    

    as written in the references: Button.PrintObject Property.


    Instead of ActiveSheet I recommend to use ThisWorkbook.Worksheets("Sheet1") to fully specify the worksheet.