Results 1 to 6 of 6

Thread: Background Image on word doc

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    243

    Background Image on word doc

    I'm putting some data from my vb app to word doc using the code

    Dim WordDoc As Word.Document
    newfile$ = App.Path + "\Temp.doc"
    Set MyWord = CreateObject("Word.Application")
    Set WordDoc = MyWord.Documents.Add
    MyWord.Visible = True
    MyWord.Activate


    MyWord.Selection.TypeText "bla..bla..bla..."
    '//MY TEXT ON FULL PAGE



    Set WordDoc = Nothing
    Set MyWord = Nothing


    Now I've to put an faded image (like watermark) on the background of the page and text on it. how it's possible. can anyone suggest.

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Background Image on word doc

    Example:
    Code:
    Private Sub Command1_Click()
        Dim MyWord As Word.Application, WordDoc As Word.Document
        
        Set MyWord = New Word.Application
        Set WordDoc = MyWord.Documents.Add
        
        AddWaterMark WordDoc
        
        MyWord.Visible = True
    End Sub
    
    
    Private Sub AddWaterMark(pDoc As Word.Document)
        pDoc.Shapes.AddTextEffect 0, "ULTRA SECRET", "Century Gothic", 1, False, False, 0, 0
        pDoc.Shapes(1).Name = "PowerPlusWaterMarkObject1"
        pDoc.Shapes(1).TextEffect.NormalizedHeight = False
        pDoc.Shapes(1).Line.Visible = False
        pDoc.Shapes(1).Fill.Visible = True
        pDoc.Shapes(1).Fill.Solid
        pDoc.Shapes(1).Fill.ForeColor.RGB = RGB(0, 255, 255)
        pDoc.Shapes(1).Fill.Transparency = 0.8
        pDoc.Shapes(1).Rotation = 315
        pDoc.Shapes(1).LockAspectRatio = True
        pDoc.Shapes(1).Height = 80
        pDoc.Shapes(1).Width = 520
        pDoc.Shapes(1).WrapFormat.AllowOverlap = True
        pDoc.Shapes(1).WrapFormat.Side = wdWrapNone
        pDoc.Shapes(1).WrapFormat.Type = 3
        pDoc.Shapes(1).RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
        pDoc.Shapes(1).RelativeVerticalPosition = wdRelativeVerticalPositionMargin
        pDoc.Shapes(1).Left = wdShapeCenter
        pDoc.Shapes(1).Top = wdShapeCenter
    End Sub
    This example will create a WaterMark for 1 page. First param in AddTextEffect method is the Text effect applied. You can play with this from Word itself by saving a Macro, adding the watermark and then seeing the code generated in the macro Visual Basic Editor. Here is how to do it from Word, it shouldn't be too much difference between Office versions: How to create watermarks in Word 2002 and in Word 2003

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    243

    Re: Background Image on word doc

    I've to show my own image on watermark

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Background Image on word doc

    Code:
    Private Sub AddWaterMark(pDoc As Word.Document, PicPath As String)
    Dim Sh As Word.Shape
    
        Set Sh = pDoc.Shapes.AddPicture(PicPath, False, True)
        
        Sh.Name = "WordPictureWatermark1"
        Sh.PictureFormat.Brightness = 0.7
        Sh.PictureFormat.Contrast = 0.1
        Sh.LockAspectRatio = True
        
        Sh.Height = 80
        Sh.Width = 520
        Sh.WrapFormat.AllowOverlap = True
        Sh.WrapFormat.Side = wdWrapNone
        Sh.WrapFormat.Type = 3
        Sh.RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
        Sh.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
        Sh.Left = wdShapeCenter
        Sh.Top = wdShapeCenter
    End Sub
    PLay with Brightness and Contrast values untill you get what you want, call it sending Word Document and Path to picture as parameter, like this:
    Code:
    AddWaterMark WordDoc, "C:\MyPic.jpg"

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    243

    Re: Background Image on word doc

    Sorry, bt it's now showing on my doc

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Background Image on word doc

    the correct way to place a watermark is to insert it into the header for the page (first page only or all pages), this allows normal document text to be printed across the top of it
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width