hi all...
i have several pictures/object then copy paste into ms word. i need macro/vba can do to setting automatically the picture layout after pasting in ms word with desired setting/layout like this:
1) Position:
Horizontal
- absolut 1,96 cm ---> (to the right of Column)
Vertical
- absolut 0,18 cm ---> (below Paragraph)
2) Size
Height (absolute) 13,24 cm
Width (absolute) 23,41 cm
3) Scale
Height 84%, Width 84%
for detail information attachment this file
anyone help me out, thanks in advance
susan
VBA: Setting Layout Pictures With Automatically in Ms Word
-
- 3StarLounger
- Posts: 240
- Joined: 17 Feb 2022, 05:16
VBA: Setting Layout Pictures With Automatically in Ms Word
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA: Setting Layout Pictures With Automatically in Ms Word
The size and scale requirements appear to be contradictory.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 240
- Joined: 17 Feb 2022, 05:16
Re: VBA: Setting Layout Pictures With Automatically in Ms Word
hi hans.
you're right size & scale is contradictory..
i think can use scale Height 84%, Width 84% without size number setting
you're right size & scale is contradictory..
i think can use scale Height 84%, Width 84% without size number setting
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA: Setting Layout Pictures With Automatically in Ms Word
Hmmm... anyone else? I cannot get VBA to set this correctly. If I specify an absolute position, Word changes it to a percentage...
Best wishes,
Hans
Hans
-
- PlutoniumLounger
- Posts: 15636
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: VBA: Setting Layout Pictures With Automatically in Ms Word
I am not sure that I understand this problem.
I downloaded the docx, saved it as a Word2003 doc, exited then reloaded Word2003 opening the doc. I can manually (no VBA yet) scale the size of the (first) image to 84%, which forces a Height of 11.12cm and a Width of 10.52cm; so I think that the size/scale etc is not a problem.
In Word2003, right-click, Format Picture, Layout, Advanced I can set up like this:- Am I close to requirements? I am not sure how to prove that I have laid out the image correctly. Perhaps interim Large Values might help me/us to see if in Word2003 the appropriate settings can be made to stick?
Once we are sure that I understand the problem/requirements I will try replicating the action in VBA.
Cheers, Chris
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle
-
- 3StarLounger
- Posts: 240
- Joined: 17 Feb 2022, 05:16
Re: VBA: Setting Layout Pictures With Automatically in Ms Word
if my question is difficult, i think for this moment this code can be reference (code work fine for me)
but found the problem, if picture more than 1? you must select pict/shape 1 by 1 before running the code
how to combine or if possible to resize pict with multiple selected all pict at once?
Code: Select all
Sub ResizePics()
Dim shp As Word.Shape
Dim ishp As Word.InlineShape
If Word.Selection.Type <> wdSelectionInlineShape And _
Word.Selection.Type <> wdSelectionShape Then
Exit Sub
End If
If Word.Selection.Type = wdSelectionInlineShape Then
Set ishp = Word.Selection.Range.InlineShapes(1)
ishp.LockAspectRatio = False
ishp.Height = CentimetersToPoints(13.78)
ishp.Width = CentimetersToPoints(23.17)
Else
If Word.Selection.Type = wdSelectionShape Then
Set shp = Word.Selection.ShapeRange(1)
shp.LockAspectRatio = False
shp.Height = CentimetersToPoints(11.78)
shp.Width = CentimetersToPoints(23.17)
End If
End If
End Sub
how to combine or if possible to resize pict with multiple selected all pict at once?
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA: Setting Layout Pictures With Automatically in Ms Word
Try this:
Code: Select all
Sub ResizePics()
Dim shp As Shape
Dim ishp As InlineShape
For Each shp In ActiveDocument.Shapes
shp.LockAspectRatio = False
shp.Height = CentimetersToPoints(11.78)
shp.Width = CentimetersToPoints(23.17)
Next shp
For Each ishp In ActiveDocument.InlineShapes
ishp.LockAspectRatio = False
ishp.Height = CentimetersToPoints(13.78)
ishp.Width = CentimetersToPoints(23.17)
Next ishp
End Sub
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 240
- Joined: 17 Feb 2022, 05:16
Re: VBA: Setting Layout Pictures With Automatically in Ms Word
hi hans, thanks a lot..
but i want to add criteria setting:
1. Horizontal (Absolute position) is 0,5 cm
2. Vertical (Absolute position) is 1,2 cm
but i want to add criteria setting:
1. Horizontal (Absolute position) is 0,5 cm
2. Vertical (Absolute position) is 1,2 cm
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA: Setting Layout Pictures With Automatically in Ms Word
That is only possible for shapes, not for inline shapes. But I don't know how to do that.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: VBA: Setting Layout Pictures With Automatically in Ms Word
Inlineshapes would need conversion to Shapes:
Code: Select all
Sub ReFormatPics()
Dim Shp As Shape
With ActiveDocument
Do While .InlineShapes.Count > 0
.InlineShapes(1).ConvertToShape
Loop
For Each Shp In .Shapes
With Shp
.LockAspectRatio = False
.Height = CentimetersToPoints(11.78)
.Width = CentimetersToPoints(23.17)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
.RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
.Top = CentimetersToPoints(0.18)
.Left = CentimetersToPoints(1.96)
End With
Next Shp
End With
End Sub
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- 3StarLounger
- Posts: 240
- Joined: 17 Feb 2022, 05:16
Re: VBA: Setting Layout Pictures With Automatically in Ms Word
hi paul, thank you very much!!! Working well.