Word--picture regularization macro code

When writing Word reports, especially some road test reports and project summary reports, there are a lot of pictures involved, which are often different in size and very unsightly. It takes time to manually adjust one by one (even if the first is adjusted) It is troublesome to press the F4 shortcut one by one after the size of a picture. Here is a macro for adjusting the uniform size of Word pictures.



Source code












Sub FormatPics() Dim iSha As InlineShape For Each iSha In ActiveDocument.InlineShapes If iSha.Type = wdInlineShapePicture Then iSha.LockAspectRatio = msoFalse #Do not lock the aspect ratio iSha.Width = CentimetersToPoints(12) #Set the width of the picture in cm iSha. Height = CentimetersToPoints(8) #Set the height of the picture in centimeters End If NextEnd Sub


Operation method


Open the Word document to be formatted:

image

Alt + F11 shortcut, VB open interface, click on the 'View' menu under 'code window' , the paste on the above code, and then save

image

Click the run button, or run under the run menu, or press the F5 shortcut key. After running, all pictures in the Word are set to the same size:

image

Or exit the VB editing interface, click Macro under the View menu of the Word document, a macro dialog box will pop up, and the code macro you just wrote can also be run here:

image


Guess you like

Origin blog.51cto.com/15069490/2578662