?
Solved

Create watermark in word with vba from access

Posted on 2008-10-09
2
Medium Priority
?
801 Views
Last Modified: 2012-08-13
I have an access database that is pushing a lot of information into a word doc using bookmarks in the word doc.  The last thing i need to do is insert a watermark into the document if a condition exists.  The conditional part is easy, what i am having problems with is just inserting the watermark.  I can record the macro and have that work from within word but i want to run it all from access with no macro in the word doc.  I'm sure its getting lost somewhere in the activedocument. lines but I am just beating my head against a wall at this point. The watermark ideally is angled text that will repeat on all pages. Thanks

with doc.
          ' Populating word doc
end with
0
Comment
Question by:rkremser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Assisted Solution

by:wobbled
wobbled earned 150 total points
ID: 22679252
I have almost got this to work - but I get an error on the line:

Selection.HeaderFooter.Shapes("PowerPlusWaterMarkObject1").Select

If anyone else can see what is causing this then please help out
Sub WordDocFromExcel()
' to test this code, paste it into an Excel module add a reference to the Word-library
' create a new folder named C:\Foldername or edit the filnames in the code
 
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim wrdWin As Object
Dim i As Integer
 
    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
    Set wrdDoc = wrdApp.Documents.Add ' create a new document
    Set wrdWin = wrdApp.ActiveWindow
    ' or
    'Set wrdDoc = wrdApp.Documents.Open("C:\Foldername\Filename.doc")
    ' open an existing document
    ' example word operations
    With wrdDoc
        For i = 1 To 100
            .Content.InsertAfter "Here is a example test line #" & i
            .Content.InsertParagraphAfter
        Next i
        
        wrdDoc.Sections(1).Range.Select
        wrdWin.ActivePane.View.SeekView = wdSeekCurrentPageHeader
        
        Selection.HeaderFooter.Shapes("PowerPlusWaterMarkObject1").Select
        
        With Selection.ShapeRange
            .TextEffect.Text = "ASAP"
            .TextEffect.FontSize = 1
            .TextEffect.FontName = "Times New Roman"
            .Line.Visible = False
            .Fill.Visible = True
            .Fill.Solid
            .Fill.ForeColor.RGB = RGB(192, 192, 192)
            .Fill.Transparency = 0.5
            .Rotation = 315
            .LockAspectRatio = True
            .Height = CentimetersToPoints(6.88)
            .Width = CentimetersToPoints(13.77)
            .WrapFormat.AllowOverlap = True
            .WrapFormat.Side = wdWrapNone
            .WrapFormat.Type = 3
            .RelativeHorizontalPosition = _
                wdRelativeVerticalPositionMargin
            .RelativeVerticalPosition = _
                wdRelativeVerticalPositionMargin
            .Left = wdShapeCenter
            .Top = wdShapeCenter
        End With
            wrdWin.ActivePane.View.SeekView = wdSeekMainDocument
        
        If Dir("C:\Foldername\MyNewWordDoc.doc") <> "" Then
            Kill "C:\Foldername\MyNewWordDoc.doc"
        End If
        .SaveAs ("C:\Foldername\MyNewWordDoc.doc")
        .Close ' close the document
    End With
    
    wrdApp.Quit ' close the Word application
    
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
    Set wrdWin = Nothing
End Sub

Open in new window

0
 
LVL 6

Accepted Solution

by:
zipa72 earned 225 total points
ID: 22679555
rkremser,

I've created a sample how to create new Word document from Access, insert picture into header of that document, change properties for watermark, change position of the picture, close the document and dispose of objects (don't forget to do that!)

HTH

B.
Sub test()
  Dim ap As New Word.Application
  Dim doc As Word.Document
 
  ' create new word document
  Set doc = ap.Documents.Add(, , , Visible)
 
  ' insert picture in document header
  ap.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
  ap.Selection.InlineShapes.AddPicture FileName:="somepicture.gif", _
      LinkToFile:=False, SaveWithDocument:=True
  ap.Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
 
  ' make watermark
  ap.Selection.InlineShapes(1).PictureFormat.Brightness = 0.85
  ap.Selection.InlineShapes(1).PictureFormat.Contrast = 0.15
 
  ' convert from inlineshape to shape and set position
  ap.Selection.InlineShapes(1).ConvertToShape
  ap.Selection.ShapeRange.Top = 150
  ap.Selection.ShapeRange.Left = 150
 
  ' return from header view
  ap.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
 
  ' clean up
  doc.SaveAs "test.doc"
  ap.Quit
  Set doc = Nothing
  Set ap = Nothing
End Sub

Open in new window

0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

771 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