Solved

word template flickering

Posted on 2008-10-09
3
262 Views
Last Modified: 2012-05-05
In my word template I have several command buttons one of them is print button.
When I press this print button I first validate entries then hide buttons then print out document then unhide button.
This work fine but when I press button document is flickering and flashing for several seconds. This is disturbing and annoying.

How to eliminate this flickering?
Here is my code in print button click event.
 
Private Sub cmdPrint_Click()

'First we validate entries
Dim EntriesComplete As Boolean
EntriesComplete = False
'Call validate procedure ValidateServiceEntries
EntriesComplete = ValidateServiceEntries

 Dim ilsh As InlineShape

If EntriesComplete = True Then
    For Each ilsh In ActiveDocument.InlineShapes
    If ilsh.Type = wdInlineShapeOLEControlObject Then
        Select Case ilsh.OLEFormat.Object.Name
           
        Case "cmdPrint", "cmdSandEmail", "cmdSalesmanInfo", "cmdEditCustomer", _
        "cmdEditCustomer", "cmdEditContractor", "cmdComment", "cmdSave", _
        "lblEmailWarning", "cmdClearAndStartNew"
        ilsh.Range.Font.Hidden = True
        End Select
    End If
   
        Next ilsh
 print document without cm buttons
    ActiveDocument.PrintOut

put buttons back
    For Each ilsh In ActiveDocument.InlineShapes
   
    If ilsh.Type = wdInlineShapeOLEControlObject Then
        Select Case ilsh.OLEFormat.Object.Name
        Case "cmdPrint", "cmdSandEmail", "cmdSalesmanInfo", "cmdEditCustomer", _
        "cmdEditCustomer", "cmdEditContractor", "cmdComment", "cmdSave", _
        "lblEmailWarning", "cmdClearAndStartNew"
        ilsh.Range.Font.Hidden = False
        End Select
    End If
   
    Next ilsh
Else
    MsgBox "Can not Print Please first correct entries"
    Exit Sub
End If

End Sub
0
Comment
Question by:Taras
  • 2
3 Comments
 
LVL 23

Expert Comment

by:irudyk
ID: 22683023
Try turning the screen updating off and then back on using Application.ScreenUpdating = False and Application.ScreenUpdating = True
Try the revised code below

Private Sub cmdPrint_Click()
 

Application.ScreenUpdating = False 
 

'First we validate entries

Dim EntriesComplete As Boolean

EntriesComplete = False

'Call validate procedure ValidateServiceEntries

EntriesComplete = ValidateServiceEntries
 

Dim ilsh As InlineShape
 

If EntriesComplete = True Then

    For Each ilsh In ActiveDocument.InlineShapes

    If ilsh.Type = wdInlineShapeOLEControlObject Then

        Select Case ilsh.OLEFormat.Object.Name

           

        Case "cmdPrint", "cmdSandEmail", "cmdSalesmanInfo", "cmdEditCustomer", _

        "cmdEditCustomer", "cmdEditContractor", "cmdComment", "cmdSave", _

        "lblEmailWarning", "cmdClearAndStartNew"

        ilsh.Range.Font.Hidden = True

        End Select

    End If

    

        Next ilsh

    'print document without cm buttons

    ActiveDocument.PrintOut
 

    'put buttons back

    For Each ilsh In ActiveDocument.InlineShapes

    

    If ilsh.Type = wdInlineShapeOLEControlObject Then

        Select Case ilsh.OLEFormat.Object.Name

        Case "cmdPrint", "cmdSandEmail", "cmdSalesmanInfo", "cmdEditCustomer", _

        "cmdEditCustomer", "cmdEditContractor", "cmdComment", "cmdSave", _

        "lblEmailWarning", "cmdClearAndStartNew"

        ilsh.Range.Font.Hidden = False

        End Select

    End If

    

    Next ilsh

Else

    MsgBox "Can not Print Please first correct entries"

End If
 

Application.ScreenUpdating = True
 

End Sub

Open in new window

0
 

Author Comment

by:Taras
ID: 22684014
I did it but still the same
0
 
LVL 23

Accepted Solution

by:
irudyk earned 500 total points
ID: 22684279
Hmm, well setting the ScreenUpdating usually does the job.  If not in your case, then I'd have to see a sample file to be able to test with.  The other option is to set the document to print Draft Output.  Doing so will not print the buttons without you having to the button's font hidden (which I'm presuming is the cause of the flickering).  So something like
Private Sub cmdPrint_Click()

 

Application.ScreenUpdating = False 

 

'First we validate entries

Dim EntriesComplete As Boolean

EntriesComplete = False

'Call validate procedure ValidateServiceEntries

EntriesComplete = ValidateServiceEntries

 

Dim ilsh As InlineShape

 

If EntriesComplete = True Then

    Options.PrintDraft = True

    ActiveDocument.PrintOut

    Options.PrintDraft = False

Else

    MsgBox "Can not Print Please first correct entries"

End If

 

Application.ScreenUpdating = True

 

End Sub

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now