簡體   English   中英

使用VBA防止在Word .doc中打印圖像

[英]Using VBA to prevent image printing in Word .doc

我設置了一個在后台具有8.5 x 11圖像的簡歷(如果需要,可以將其設置為水印)。 現在,我想對其進行設置,以使其不會自動打印背景圖像,從而使雇主不必跳圈。 在網上查看后,我注意到這可能必須使用VBA和模板進行設置。 任何現場或任何願意解決此問題的人,將不勝感激。

我幾乎只是希望我的Word文檔不要打印圖像或水印,而不必讓打印它的人進行任何設置。(不必同時使用)

您真的需要VBA嗎?

若要在Word 2010中禁用背景色和圖像的打印,只需按照以下步驟

點擊文件| 選項

您將看到一個“ Word選項”對話框。

在顯示標簽下,只需取消選中“打印背景顏色和圖像”

不知道為什么,但是這很正常。

Public WithEvents appWord As Word.Application

Private Sub Document_Open()
    Set appWord = Application
    ' Not sure if your image is a shape or inlineshape, so...
    If ThisDocument.Shapes.Count Then
        ' First Shape is now visible
        ThisDocument.Shapes(1).Visible = msoTrue
    ElseIf ThisDocument.InlineShapes.Count Then
        ' First inlineshpae has medium brightness
        ThisDocument.InlineShapes.Item(1).PictureFormat.Brightness = 0.5
    End If
End Sub

Private Sub appWord_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)

 Dim intResponse As Integer

 intResponse = MsgBox("This document contains a background image. " & _
    "Would you like to hide it before printing?", vbYesNo, _
    "Hide Background Image?")
     If intResponse = vbYes Then
         hide_images

     ElseIf intResponse = vbNo Then

        show_images
     End If
End Sub

Sub hide_images()

    Application.DisplayStatusBar = True
    With ActiveWindow
        .DisplayHorizontalScrollBar = True
        .DisplayVerticalScrollBar = True
        .DisplayLeftScrollBar = False
        .StyleAreaWidth = CentimetersToPoints(0)
        .DisplayVerticalRuler = True
        .DisplayRightRuler = False
        .DisplayScreenTips = True
        With .View
            .ShowAnimation = True
            .Draft = False
            .WrapToWindow = False
            .ShowPicturePlaceHolders = False
            .ShowFieldCodes = False
            .ShowBookmarks = False
            .FieldShading = wdFieldShadingWhenSelected
            .ShowTabs = False
            .ShowSpaces = False
            .ShowParagraphs = False
            .ShowHyphens = False
            .ShowHiddenText = False
            .ShowAll = True
            .ShowDrawings = True
            .ShowObjectAnchors = False
            .ShowTextBoundaries = False
            .ShowHighlight = True
        End With
    End With
    With Options
        .UpdateFieldsAtPrint = False
        .UpdateLinksAtPrint = False
        .DefaultTray = "Druckereinstellungen verwenden"
        .PrintBackground = True
        .PrintProperties = False
        .PrintFieldCodes = False
        .PrintComments = False
        .PrintHiddenText = False
        .PrintDrawingObjects = False
        .PrintDraft = False
        .PrintReverse = False
        .MapPaperSize = True
    End With
    With ActiveDocument
        .PrintPostScriptOverText = False
        .PrintFormsData = False
    End With
End Sub

Sub show_images()

    With Options
        .UpdateFieldsAtPrint = False
        .UpdateLinksAtPrint = False
        .DefaultTray = "Druckereinstellungen verwenden"
        .PrintBackground = True
        .PrintProperties = False
        .PrintFieldCodes = False
        .PrintComments = False
        .PrintHiddenText = False
        .PrintDrawingObjects = True
        .PrintDraft = False
        .PrintReverse = False
        .MapPaperSize = True
    End With
    With ActiveDocument
        .PrintPostScriptOverText = False
        .PrintFormsData = False
    End With
End Sub

歡呼瑪汀

我將以下(簡短)過程用作功能區擴展名,以在文檔標題中顯示/隱藏徽標,以便用戶可以在創建打印/ pdf之前進行切換。

Sub ShowHideLogoInHeader

本地錯誤處理程序(非關鍵)

On Local Error GoTo ErrHandler

暗淡的shaperange

Dim myStory As ShapeRange
Set myStory = ActiveDocument.StoryRanges(wdFirstPageHeaderStory).ShapeRange
myStory.Visible = Not myStory.Visible

Exit Sub

ErrHandler:在調試中報告錯誤(單獨的功能)

ReportError "modRibbon - ToonOfVerbergLogo"
Err.Clear
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM