Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 09-13-2016, 04:54 AM
macropod's Avatar
macropod macropod is offline Border with random colors Windows 7 64bit Border with random colors Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If you use code like:
Code:
Sub AddRandomBorder()
Application.ScreenUpdating = False
Dim Rng As Range, i As Long, Shp As Shape, iWidth As Long, iHeight As Long
With ActiveDocument
  With .Sections(1).PageSetup
    iWidth = Int(.PageWidth - 40)
    iHeight = Int(.PageHeight - 40)
  End With
  For i = 1 To .ComputeStatistics(wdStatisticPages)
    Set Rng = .GoTo(What:=wdGoToPage, Name:=i)
    Set Shp = .Shapes.AddShape(Type:=1, Top:=0, Left:=0, Width:=iWidth, _
      Height:=iHeight, Anchor:=Rng.GoTo(What:=wdGoToBookmark, Name:="\page"))
    With Shp
      .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
      .RelativeVerticalPosition = wdRelativeVerticalPositionPage
      .Top = 20
      .Left = 20
      .Line.ForeColor = RGB(Rnd() * 255, Rnd() * 255, Rnd() * 255)
      .Line.Weight = 3
      .Fill.Transparency = 1
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
which should execute somewhat more quickly on a large document, then, given that you know the sizes from the code that adds the shapes, you could delete them using code like:
Code:
Sub DelRandomBorders()
Application.ScreenUpdating = False
Dim i As Long, iWidth As Long, iHeight As Long
With ActiveDocument
  With .Sections(1).PageSetup
    iWidth = Int(.PageWidth - 40)
    iHeight = Int(.PageHeight - 40)
  End With
  For i = .Shapes.Count To 1 Step -1
    With .Shapes(i)
      If .Height = iHeight Then
        If .Width = iWidth Then .Delete
      End If
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Border with random colors Aligning Page Border with Table border without losing formatting :mad: l39linden Word Tables 5 10-04-2013 02:06 AM
Border with random colors Bar colors ketanco Project 1 03-30-2013 08:24 AM
Border with random colors Unable to change font colors from theme colors choy Word 3 08-01-2012 09:12 PM
random pop up wont go away 464646 OneNote 0 05-01-2012 04:34 AM
Only Random Border Lines Printing! TheCatSpeaks Excel 4 05-17-2010 07:39 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft