[AccessD] Insert Logo Graphic at Word Bookmark - Automation code

Jurgen Welz jwelz at hotmail.com
Mon Feb 9 11:29:48 CST 2015


I've been running some automation code that inserts a graphic logo on an invoicing document.  The procedure is part of a very generic procedure that sets up a Word letterhead for one of several companies and includes a subsequent page letterhead (with a smaller logo) should the generated document exceed one page.  It looks for a bookmark in the Word template with a specific name and if it finds it, selects and deletes it and then inserts a graphic based on a path looked up from a table with fields for Company/Division name and Path (after verifying the location of the logo file).

This process has worked fine with Office 97, 2000, 2013, 2010 with Word templates of the appropriate version.  With Word 2013, the first page logo ends up in one of two places.  Either where it belongs or about 7.5 cm below.  It is misplaced about 20% of the time.  If I use the old version template (dot rather than dotx), it consistently places the logo correctly.  It is only inconsistently messed up when the template is upgraded to the 2013 version and works as it always has for at least 15 years, with Word 2013 using the 2010 template file.  One of the downsides is that Word offers to upgrade saved files when reopened and edited and the margins change and this seriously messes up some of the documents with jurats such as the statutory declaration documents which I keep saving as doc files (not docx) in code.

simplified excerpt of code:

Dim r As DAO.Recordset  'instantiation removed for simplicity
Dim owdApp As Word.Application 'Instantiation removed - passed into procedure as a parameter
Dim owdDoc As Word.Document 'Instantiation removed - passed to procedure as a parameter
Dim owdShape As Word.Shape
Dim strLogoPath As String

strLogoPath = r("LogoPath") & ""
If Len(strLogoPath) Then
    Set owdShape = owdDoc.Shapes.AddPicture(strLogoPath, _
      LinkToFile:=False, SaveWithDocument:=True)
    With owdShape
        .LockAspectRatio = msoTrue
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        .RelativeVerticalPosition = wdRelativeVerticalPositionPage
        .Height = owdApp.InchesToPoints(0.5)
        .WrapFormat.Type = wdWrapNone
        .Left = owdApp.InchesToPoints(0.5)
        .Top = owdApp.InchesToPoints(0.5)
    End With
End If


The system generates a few hundred different kinds of documents and in particular, this has been messing up my progress claim (invoice) and schedule of value documents that are produced together with required statutory declarations.  I'm liking the decrease in size of the 2013 version documents but am finding that Microsoft has found new ways of messing me up.  I hate the inconsistency I've been getting and can find no basis for it.

I'd like to get to an all 2013 solution yet accomodate a range of logos of different aspect ratios and file types.  I'm also looking for a decent free WMF converter.

Ciao
Jürgen Welz
Edmonton, Alberta
 		 	   		  


More information about the AccessD mailing list