Sub DeletePagesXtoY()
Dim startRange As Range
Dim endRange As Range
Dim iStart As Integer
Dim iEnd As Integer
iStart = 249
iEnd = 257
Set startRange = ActiveDocument.GoTo(What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=iStart)
' Set the start of page 291
Set endRange = ActiveDocument.GoTo(What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=iEnd)
' Select the range between page 230 and 290
startRange.SetRange Start:=startRange.Start, End:=endRange.Start
' Delete the selected range
startRange.Delete
End Sub
Tuesday, December 24, 2024
VBA Word - Delete pages of document between a range
The following VBA code deletes pages of Word document between a range.
VBA Word - Adjust all images in Word document
The following VBA code adjusts images in Word document:
Sub AdjustImageSize()
Dim doc As Document
Dim img As InlineShape
Dim shape As shape
Dim docWidth As Single
Set doc = ActiveDocument
docWidth = doc.PageSetup.PageWidth - doc.PageSetup.LeftMargin - doc.PageSetup.RightMargin
' Loop through all inline shapes (embedded images)
For Each img In doc.InlineShapes
If img.Width > docWidth Then
img.LockAspectRatio = msoTrue
img.Width = docWidth
End If
Next img
' Loop through all floating shapes (floating images)
For Each shape In doc.Shapes
If shape.Type = msoPicture Or shape.Type = msoLinkedPicture Then
If shape.Width > docWidth Then
shape.LockAspectRatio = msoTrue
shape.Width = docWidth
End If
End If
Next shape
End Sub
Subscribe to:
Posts (Atom)
Hot Topics
-
The @page directive The @page directive in ASP.NET Core Razor Pages is crucial because it designates a Razor file as a Razor Page, allowin...
-
Objectives To provide detailed information about ListBox Types of ListBox Using ListBox in VBA applications Please read the post till end...
-
VBA TypeOf is followed by a reference type variable or expression which returns an object data type. This object type is compared with anot...