none
Text beside picture RRS feed

  • Question

  • Good day,

    I have a script that creates Outlook signatures based on Active Directory attributes and inserts images in the signature.

    The problem I have is that when inserting the picture and then adding text after the image, it does not wrap square around it.

    The script should place the first image and write the text beside it but right now, it's inserting the image in front of the text.  Please help!!!! :D

    You will find below the VBA script :

    richTextFilePath = pathToCopyTo & sNomFichier & aTraduction(5,iLangue) & ".rtf" Set objWord = CreateObject("Word.Application") objWord.Visible = False Set objDoc = objWord.Documents.Add() Set objSelection = objWord.Selection

    Set Shape = objSelection.InlineShapes.AddPicture(appDataPath & cDossierSignature & sNomFichier & "_fichiers/" & cImagePCM).ConvertToShape Shape.Height = cImagePCMH Shape.Width = cImagePCMW Shape.Select Shape.Selection.ShapeRange.WrapFormat.Type = wdWrapSquare Shape.LockAspectRatio = True 'Nom de l'employé et titre objSelection.Font.Name = "Arial" objSelection.Font.Size = "9" objSelection.Font.Bold = True objSelection.TypeText sNom & sAcroPro & " | " & sTitre objSelection.TypeText Chr(11) 'Direction de l'employé. objSelection.Font.Name = "Arial" objSelection.Font.Size = "8" objSelection.Font.Bold = False objSelection.TypeText sDept objSelection.TypeText (Chr(11)) 'Numéro de tel de l'employé. objSelection.Font.Name = "Arial" objSelection.Font.Size = "9" objSelection.Font.Bold = True objSelection.TypeText aTraduction(4,iLangue) objSelection.Font.Name = "Arial" objSelection.Font.Size = "9" objSelection.Font.Bold = True objSelection.TypeText sTel objSelection.TypeText (Chr(11)) 'Adresse de la compagnie objSelection.Font.Name = "Arial" objSelection.Font.Size = "9" objSelection.Font.Bold = False objSelection.Font.Color = RGB(0,0,0) objSelection.TypeText aTraduction(0,iLangue) Set Shape = objSelection.InlineShapes.AddPicture(appDataPath & cDossierSignature & sNomFichier & "_fichiers/" & cImageAIPC).ConvertToShape Shape.Height = cImageAIPCH Shape.Width = cImageAIPCW 'Shape.WrapFormat.Type = wdWrapFront objSelection.TypeText Chr(11) objDoc.SaveAs richTextFilePath', RTF objWord.Quit


    • Edited by Azzurro Friday, September 16, 2016 1:03 AM
    Friday, September 16, 2016 1:02 AM

Answers

  • I recommend you create a template (dotx) and create the Word document based on the template. You setup the template fonts like you want.  Add bookmarks where you to insert text and the image.  Example:

    mydoc.Bookmarks("sig").Select
    mydoc.Bookmarks("sig").Range.Text = ""
    Selection.InlineShapes.AddPicture fileName:="C:\images\sig1.jpg"

    It is poor practice to embed font and other code in VBA.  Maintenance is a nightmare.  Keep it all in the template.  All you should be doing with VBA is inserting text and images. 

    • Marked as answer by Azzurro Monday, September 19, 2016 1:45 AM
    Friday, September 16, 2016 12:22 PM

All replies

  • I recommend you create a template (dotx) and create the Word document based on the template. You setup the template fonts like you want.  Add bookmarks where you to insert text and the image.  Example:

    mydoc.Bookmarks("sig").Select
    mydoc.Bookmarks("sig").Range.Text = ""
    Selection.InlineShapes.AddPicture fileName:="C:\images\sig1.jpg"

    It is poor practice to embed font and other code in VBA.  Maintenance is a nightmare.  Keep it all in the template.  All you should be doing with VBA is inserting text and images. 

    • Marked as answer by Azzurro Monday, September 19, 2016 1:45 AM
    Friday, September 16, 2016 12:22 PM
  • The template suggestion worked well.  Thank you for your input.

    Would you know how to make a bookmark, clickable as a hyperlink?  In my signature generation, I create 2 files a French and a English version and depending on the lingual, the legal limitation link changes....

    I could create 2 templates (French and English) and proceed the same way as you explained but don't find it very dynamic....

    Thank you

    Monday, September 19, 2016 1:48 AM
  • Personally, I would leave it at 2 templates.  I often have multiple templates that only have small differences.  This way users can easily change the templates without changing any VBA code and involving me.
    Tuesday, September 20, 2016 10:59 PM