#16
|
|||
|
|||
Nope. Something interesting though - I just made a copy of your template and opened it and tried to print. The message box appeared again, so that excited me, and it printed with the underscores in place of the placeholder text as it should. Yay!... then I tried it again and it's back to not working
So something is clearly happening that I can't explain and I'm sure it's almost impossible for you to figure out without access to my computer. I don't understand what could possibly be happening though and it's very frustrating. I'm open to any more suggestions but I suppose I'll just move on and forget about implementing this into my document. |
#17
|
||||
|
||||
It works for me - repeatedly. Did you have another document that's attached to another template containing a BeforePrint macro open at the same time?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#18
|
|||
|
|||
I have no other documents open, just that one template.
When things like this happen it really bugs me so I just want to figure it out lol. I am losing hope, however. Is there a way to debug it on my end? I'm not getting any errors or anything, it just prints with the placeholder text showing. I'll note that there is a popup for my printer indicating low ink levels, would that somehow get in the way? Seems silly but all I can think of at the moment. |
#19
|
|||
|
|||
Maybe a timing issue with the print spool. You might try:
Code:
Option Explicit Public WithEvents oApp As Word.Application Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub oApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean) Application.ScreenUpdating = False MsgBox "!" Dim CCtrl As ContentControl, i As Long 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 DoEvents Sleep 2000 .Undo i End With Cancel = True Application.ScreenUpdating = True End Sub |
#20
|
|||
|
|||
You might be right, Greg, but weird that it would work initially with the same printer popup. I hope you're right.
I just tried copying the code in but I get a Compile error: "The code in this project must be updated for use on 64-bit systems. Please review and update Declare statements and then mark them with the PtrSafe attribute." Any idea what I can do to fix it? It highlights the word "Sub" in the third line of code if that helps. |
#21
|
|||
|
|||
Replace that single Declare Sub Line with:
#If VBA7 And Win64 Then Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) #Else Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) #End If |
#22
|
||||
|
||||
Since the content controls aren't being updated, that suggests Greg's delay implementation after '.PrintOut' won't make any difference.
Here's another version of the code: Code:
Private Sub wdApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean) Application.ScreenUpdating = False Dim CCtrl As ContentControl, objUndo As UndoRecord Set objUndo = Application.UndoRecord: objUndo.StartCustomRecord With Doc For Each CCtrl In .ContentControls With CCtrl If .Type <> wdContentControlPicture And .Type <> wdContentControlCheckBox Then If .Range.Text = .PlaceholderText Then .Range.Text = "_________________________" End If End If End With Next .PrintOut objUndo.EndCustomRecord .Undo End With Cancel = True Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Content Controls | Sammie0Sue | Word | 6 | 11-06-2013 10:56 PM |
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 |
Grouping Content Controls | cksm4 | Word VBA | 2 | 03-01-2011 12:46 PM |