Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-06-2013, 06:48 AM
Sammie0Sue Sammie0Sue is offline VBA to set Content controls as non printing Windows 7 64bit VBA to set Content controls as non printing Office 2010 64bit
Novice
VBA to set Content controls as non printing
 
Join Date: Nov 2013
Posts: 21
Sammie0Sue is on a distinguished road
Default VBA to set Content controls as non printing

Hi I am creating a form that uses LOTS of content controls as it will be protected when sent to clients but it should also be able to be printed and filled in by hand so I do not want the content controls to print if they have not been selected.



I want the code to work in the back ground and do not want the clients to have to click any where for the script to run.
Reply With Quote
  #2  
Old 11-06-2013, 03:23 PM
macropod's Avatar
macropod macropod is online now VBA to set Content controls as non printing Windows 7 32bit VBA to set Content controls as non printing Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,724
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

What you would need for this to work is an event-driven 'DocumentBeforePrint' macro, coded along the lines of:
Code:
Private Sub oApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
Application.ScreenUpdating = False
Dim CCtrl As ContentControl, i As Long
MsgBox "!"
With Doc
  For Each CCtrl In .ContentControls
    With CCtrl
      If .Type <> wdContentControlPicture And .Type <> wdContentControlCheckBox Then
        If .Range.Text = .PlaceholderText Then
          i = i + 1
          .Range.Text = "_________________________"
        End If
      End If
    End With
  Next
  .PrintOut
  .Undo i
End With
Cancel = True
Application.ScreenUpdating = True
End Sub
The above code looks at all content controls (except for Pictures and CheckBoxes) and replaces any placeholder text with a series of underscores. If you prefer, you could change the placeholder text font colour to white instead. After printing, the content controls are reverted to their previous state.

The message box exists merely to demonstrate that the macro has been called - it can be deleted once you have the code working correctly.

To see how to implement such a macro, go to: Intercepting events like Save and Print
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 11-06-2013 at 11:35 PM. Reason: Added code for CheckBoxes
Reply With Quote
  #3  
Old 11-06-2013, 11:17 PM
Sammie0Sue Sammie0Sue is offline VBA to set Content controls as non printing Windows 7 64bit VBA to set Content controls as non printing Office 2010 64bit
Novice
VBA to set Content controls as non printing
 
Join Date: Nov 2013
Posts: 21
Sammie0Sue is on a distinguished road
Default

Thanks a bunch for the reply but unfortunately my content controls that have not been used still seem to be printing
Reply With Quote
  #4  
Old 11-06-2013, 11:25 PM
macropod's Avatar
macropod macropod is online now VBA to set Content controls as non printing Windows 7 32bit VBA to set Content controls as non printing Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,724
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Did you do the full event-driven macro implementation as described in the link?

If you did and it's still not working, can you attach a document to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 11-06-2013, 11:40 PM
Sammie0Sue Sammie0Sue is offline VBA to set Content controls as non printing Windows 7 64bit VBA to set Content controls as non printing Office 2010 64bit
Novice
VBA to set Content controls as non printing
 
Join Date: Nov 2013
Posts: 21
Sammie0Sue is on a distinguished road
Default

Hi yes i followed the steps but I might have done something wrong.

Sorry I am new to all of this and your help is greatly appreciated
Attached Files
File Type: zip CC.zip (27.6 KB, 4 views)
Reply With Quote
  #6  
Old 11-06-2013, 11:59 PM
macropod's Avatar
macropod macropod is online now VBA to set Content controls as non printing Windows 7 32bit VBA to set Content controls as non printing Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,724
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

I don't see any evidence of either the macro I posted or the event-driven macro implementation in your attachment.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 11-07-2013, 12:04 AM
Sammie0Sue Sammie0Sue is offline VBA to set Content controls as non printing Windows 7 64bit VBA to set Content controls as non printing Office 2010 64bit
Novice
VBA to set Content controls as non printing
 
Join Date: Nov 2013
Posts: 21
Sammie0Sue is on a distinguished road
Default

Hi sorry I had done it in my original doc.

I have now added it to the demo for you..
Attached Files
File Type: zip CC.zip (29.8 KB, 3 views)
Reply With Quote
  #8  
Old 11-07-2013, 12:38 AM
macropod's Avatar
macropod macropod is online now VBA to set Content controls as non printing Windows 7 32bit VBA to set Content controls as non printing Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,724
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

All you've done is to embed the macro I posted inside another. That will never work. What is more, there's still no evidence of the event-driven macro implementation described in the link in post #2.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 11-07-2013, 07:53 AM
gmaxey gmaxey is online now VBA to set Content controls as non printing Windows 7 32bit VBA to set Content controls as non printing Office 2010 (Version 14.0)
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,183
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

Sammie,

See if this helps: http://gregmaxey.com/word_tip_pages/...print_pht.html
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #10  
Old 11-08-2013, 12:06 AM
Sammie0Sue Sammie0Sue is offline VBA to set Content controls as non printing Windows 7 64bit VBA to set Content controls as non printing Office 2010 64bit
Novice
VBA to set Content controls as non printing
 
Join Date: Nov 2013
Posts: 21
Sammie0Sue is on a distinguished road
Default

Hi Greg

I actually came across your website and tried the 3 options but for some reason my content controls still seem to be printing

Starting to feel a bit hopeless vba is really not my strongest, I normally just used active X controls as I know they do not print. Had to use content controls this time as i am populating a drop down from sharepoint
Reply With Quote
  #11  
Old 11-09-2013, 12:09 AM
macropod's Avatar
macropod macropod is online now VBA to set Content controls as non printing Windows 7 32bit VBA to set Content controls as non printing Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,724
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

See attached template.
Attached Files
File Type: zip CCtrlBeforePrint.zip (28.9 KB, 22 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 01-12-2021, 11:18 AM
thedoost thedoost is offline VBA to set Content controls as non printing Windows 10 VBA to set Content controls as non printing Office 2016
Novice
 
Join Date: Jan 2021
Posts: 5
thedoost is on a distinguished road
Default

I know this thread is old but this is exactly what I want to do. I downloaded the template that macropod posted and it worked once for me then stopped for some reason. The first time I printed from that template the message box appeared with the "!" but it hasn't showed again since and the placeholder text still prints. Anyone have any idea what's happening?

I'm using Microsoft Office 365 64-bit and it says my Word version is 2012 Build 13530.20316 if that helps any. Thanks
Reply With Quote
  #13  
Old 01-12-2021, 12:50 PM
macropod's Avatar
macropod macropod is online now VBA to set Content controls as non printing Windows 10 VBA to set Content controls as non printing Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,724
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

That suggests you no longer have the template loaded. In Word, whatever document you want code stored in a template to run on must be both attached to and accessible to the document.

Accordingly, you need to either:
• copy all the code from the CCtrlBeforePrint template and paste into corresponding modules in your own template; or
• create the relevant documents the CCtrlBeforePrint template (which can be renamed to something more suitable and reformatted beforehand), or at least attach the existing document(s) to that template.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 01-12-2021, 01:21 PM
thedoost thedoost is offline VBA to set Content controls as non printing Windows 10 VBA to set Content controls as non printing Office 2010
Novice
 
Join Date: Jan 2021
Posts: 5
thedoost is on a distinguished road
Default

But I'm still just working from the template that you posted, I haven't even tried to put the code into my document yet. I wanted to make sure it worked first, so I'm not sure how the template would no longer be loaded? Just so I understand, should that message box appear every time I print that template document? If yes, what would cause the message box to stop appearing, other than it not being loaded? I restarted my computer to see if that might help but it hasn't.

I appreciate your time, thank you.
Reply With Quote
  #15  
Old 01-12-2021, 01:56 PM
macropod's Avatar
macropod macropod is online now VBA to set Content controls as non printing Windows 10 VBA to set Content controls as non printing Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,724
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Have you perhaps added the code to another template? If so, there may be a conflict preventing the code from running properly.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to set Content controls as non printing Content Controls Sammie0Sue Word 6 11-06-2013 10:56 PM
VBA to set Content controls as non printing Rich Text Content Controls: Formatting? tinfanide Word VBA 8 03-04-2013 04:15 AM
Macro to link 2 content controls bortonj88 Word VBA 2 08-21-2012 06:24 AM
Content Controls Form Programming beachdog Word VBA 4 09-20-2011 10:26 AM
VBA to set Content controls as non printing Grouping Content Controls cksm4 Word VBA 2 03-01-2011 12:46 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 03:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft