![]() |
#1
|
|||
|
|||
![]() Useful tip I hope! I've been converting some 2003 templates to 2010 and have wasted days trying to get my old VBA to correctly position logos in the header on the front page. It turns out the problem is that Word 2010 VBA has a bug that means when adding a shape it will always anchor to the page even if you specify otherwise (i.e. it ignores the fact you're trying to anchor to column, margin, etc). I finally found a posting (elsewhere) that has solved the problem. The solution is to insert as an inline shape and then convert it to a shape (sample code below). Note that this bug only seems to affect the first page of a document. Also, 2003 documents opened in compatibility mode are not affected by the anchor bug and continue to work correctly even if saved as 2010 format so I've had to come up with two parallel solutions for existing and for new documents (just to add to the fun!). I expect someone will come back and say I should ALWAYS use inline shapes instead of shapes unless I want to use Word's text flow/desktop publishing options - and you'd be right except the problem I have is that, to be positioned correctly, the logos have to sit in the margin outside of any existing text. Code:
Set inlshpCompanyLogo = ActiveDocument.InlineShapes.AddPicture _ (FileName:=strLogoName, _ LinkToFile:=False, SaveWithDocument:=True, Range:=Selection.Range) Set shpCompanyLogo = inlshpCompanyLogo.ConvertToShape With shpCompanyLogo .LockAnchor = True .Left = CentimetersToPoints(snglLeftOffset) .Top = CentimetersToPoints(snglTopOffset) etc... End With Last edited by macropod; 02-04-2014 at 06:59 PM. Reason: Added code tags & formatting |
#2
|
||||
|
||||
![]()
The following works for me:
Code:
Dim Rng As Range With ActiveDocument Set Rng = .Sections.First.Headers(wdHeaderFooterPrimary).Range.Characters.First Set shpCompanyLogo = .Shapes.AddPicture(FileName:=strLogoName, LinkToFile:=False, SaveWithDocument:=True, _ Anchor:=Rng, Left:=CentimetersToPoints(snglLeftOffset), Top:=CentimetersToPoints(snglTopOffset)) End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
picture shapes in word 2010 | sgrund | Word | 5 | 01-30-2014 11:45 PM |
![]() |
pptdiva | PowerPoint | 1 | 10-01-2013 05:14 AM |
![]() |
namedujour | Word | 0 | 08-16-2012 12:57 PM |
![]() |
sharks | Word | 1 | 09-08-2011 04:24 AM |
Paste not working correctly Word 2010 | wapanap | Word | 0 | 09-13-2010 06:29 PM |