View Single Post
 
Old 12-15-2016, 07:22 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Create two images - one being they picture you wish to show, the other blank. Then add a bookmark where you want the image to appear, and run the following function to place the picture or the blank image in the bookmark according to the value of the checkbox. If you employ a checkbox content control you can use the CC exit even to check the value of the check box and run the function with the appropriate image for the value of the checkbox. The image will only print if it is actually displayed in the document.

Code:
Public Sub ImageToBM(strBMName As String, strImagePath As String)
'Graham Mayor - http://www.gmayor.com
Dim oRng As Range
Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(strImagePath) Then
        With ActiveDocument
            On Error GoTo lbl_Exit
            Set oRng = .Bookmarks(strBMName).Range
            oRng.Text = ""
            oRng.InlineShapes.AddPicture _
                    FileName:=strImagePath, LinkToFile:=False, _
                    SaveWithDocument:=True
            oRng.End = oRng.End + 1
            oRng.Bookmarks.Add strBMName
        End With
    End If
lbl_Exit:
    Set fso = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote