VBA to change Print Object property of a picture

nickthebizz

New Member
Joined
Jan 24, 2021
Messages
22
Office Version
  1. 2016
Platform
  1. Windows
Hi there

I need some help to write a code which I can assign to a button in excel and do the following

I have a workbook with a few sheets. On the top left corner of each sheet I have a pictures which acts as a header for my printed page. The thing i need is to
add a button where i can change the printobject to false in all pictures in the workbook(note that this pictures-Header is the same one in all sheets). So with this way I can choose to either print
all sheets without the pictures or if I would like to print all pages with the picture.

Does anyone have any idea how I could make this?

thank you

Nickthebizz
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
This might get you started. Note: it assumes your pictures are of type object. If not, I don't know if this would work. You'd need to change the sheet reference either by name or use ActiveSheet if the code is in a sheet module. This code would change this property in all shapes that are part of the loop. If you have some that you don't want to be affected, you'd need a list (an array is probably better) of shape names that you only want to affect. I'd put this code in a separate sub that will accept the shape name(s) and act on them. The line that sets the print property will cycle the property from true to false and back.
VBA Code:
Dim obj As Object
For Each obj In Sheets("Sheet 3").DrawingObjects
     'Debug.Print obj.Name & "   " & obj.printObject
     obj.printObject = Not obj.printObject
Next
 
Upvote 0
Solution
This might get you started. Note: it assumes your pictures are of type object. If not, I don't know if this would work. You'd need to change the sheet reference either by name or use ActiveSheet if the code is in a sheet module. This code would change this property in all shapes that are part of the loop. If you have some that you don't want to be affected, you'd need a list (an array is probably better) of shape names that you only want to affect. I'd put this code in a separate sub that will accept the shape name(s) and act on them. The line that sets the print property will cycle the property from true to false and back.
VBA Code:
Dim obj As Object
For Each obj In Sheets("Sheet 3").DrawingObjects
     'Debug.Print obj.Name & "   " & obj.printObject
     obj.printObject = Not obj.printObject
Next
Dear Micron, I have added the code and it works perfect!
 
Upvote 0
Glad I could help & thanks for the recognition.
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top