Graphic Object

Use the Graphic object to place a picture in the header or footer area of an Excel worksheet. There are six properties of the PageSetup object (Center-FooterPicture, CenterHeaderPicture, LeftFooterPicture, LeftHeader-Picture, RightFooterPicture, and RightHeaderPicture) that can return the Graphic object. The following procedure displays the File Picker dialog box where the user can select a picture file. Next, the file is inserted in the left header of the active sheet. Notice that to make the picture visible, you must set the LeftHeader property to the following string: "&G." To make this procedure more user friendly, modify it so that it asks the user in which of the six areas to display the picture.

Sub AddWatermarkImage()

Dim strFilename As String

With Application.FileDialog(msoFileDialogFilePicker) .Title = "Custom image selection" .AllowMultiSelect = False

.Filters.Add "Pictures", "*.gif; *.jpg; *.jpeg; *.bmp", 1 .InitialView = msoFileDialogViewThumbnail If .Show = -1 Then strFilename = .SelectedItems(1) With ActiveSheet.PageSetup With .LeftHeaderPicture .Filename = strFilename .Brightness = 0.85 .ColorType = msoPictureWatermark .Contrast = 0.15 .Height = 72 .Width = 72 End With

.TopMargin = Application.InchesToPoints(1.25) .LeftHeader = "&G"

End With End If End With End Sub

0 0

Post a comment