Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Newsgroup Archive
Word Newsgroups
Word VBA
Macro for Picture size and crop, layout and position in table.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="john.b.roberts, post: 7409156"] After many hours of struggling to achieve something similar (paste a graphic from the clipboard into a table cell, in a document section that is formatted with two columns... Set the graphic a bit below the paragraph the insertion point was in when the macro started, and center it in the column (now, on reflection, I'm not sure if the "center" action relates to the [I]table[/I] column, or the [I]section/page[/I] column, but the result looks as desired so...) Here is my code... (note error handling omitted - and I've added comments and made a few small changes in this post, so use at your own risk!) [code] Sub AddPicture() ' Dim rng As Word.Range Dim Ishp As InlineShape Dim shp As Shape Dim rngPar As Word.Range Dim rngParEnd As Word.Range Dim sglTop As Single 'remember the current selection point Set rng = Selection.Range 'set two objects to the current paragraph Set rngPar = Selection.Range.Paragraphs(1).Range Set rngParEnd = Selection.Range.Paragraphs(1).Range 'My insertion point is always at the end of the cell - exclude the end of cell marker from each of the ranges rngPar.MoveEnd wdCharacter, -1 rngParEnd.MoveEnd wdCharacter, -1 'Set the "end" range object to the last character in the paragraph rngParEnd.Collapse wdCollapseEnd rngParEnd.MoveStart wdCharacter, -1 'Work out how far apart (vertically) the first and last characters in the paragraph are, and add 20 points (for padding - a bit of white space looks good) sglTop = rngParEnd.Information(wdVerticalPositionRelativeToPage) - rngPar.Information(wdVerticalPositionRelativeToPage) + 20 'Paste the shape (already manually placed in the clipboard) at the insertion point rng.Paste 'set an inline shape object reference Set Ishp = rng.InlineShapes(1) 'convert to a shape object and set a reference Set shp = Ishp.ConvertToShape With shp .LayoutInCell = True 'These two work together, as I understand it .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph .Top = sglTop 'These two also work together, as I understand it .RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn .Left = wdShapeCenter 'Set the word-wrap (that's half the reason for converting from inLineShape to (plain) Shape - so it can have wrapping .WrapFormat.AllowOverlap = False .WrapFormat.Type = wdWrapTopBottom .WrapFormat.DistanceBottom = CentimetersToPoints(0.2) .WrapFormat.DistanceTop = CentimetersToPoints(0.2) 'Put a border around it .Line.Weight = 0.75 .Line.DashStyle = msoLineSolid .Line.Style = msoLineSingle .Line.Transparency = 0# .Line.Visible = msoTrue .Line.ForeColor.RGB = RGB(0, 0, 0) .Line.BackColor.RGB = RGB(255, 255, 255) End With 'Re-Instate previous selection rng.Select End Sub [/code] [/QUOTE]
Verification
Post reply
Forums
Archive
Newsgroup Archive
Word Newsgroups
Word VBA
Macro for Picture size and crop, layout and position in table.
Top