Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MsWord Documents formatting with a macro

Status
Not open for further replies.

cramd

Programmer
Mar 28, 2001
214
US
I have a folder with 90+ documents in it. I would like to open the folder and have a macro run that would change the formatting so that every document will now have a 3 inch top margin and a 2 inch bottom margin. I have worked with Excel macros, but I'm confused as to how I read each MSWORD document in the folder to change the format options. Any suggestions to get me started would be appreciated.

Thanks,

Diane
 
Code:
Option Explicit

Sub test()
  Dim sFolder As String
  Dim sFile As String
  Dim oDoc As Word.Document
  
  sFolder = "C:\My Documents\"
  
  sFile = Dir(sFolder & "*.doc")
  Do While sFile <> &quot;&quot;
    StatusBar = &quot;processing &quot; & sFile
    Set oDoc = GetObject(sFolder & sFile)
    With oDoc.PageSetup
      .BottomMargin = InchesToPoints(2)
      .TopMargin = InchesToPoints(3)
    End With
    oDoc.Save
    Set oDoc = Nothing
    sFile = Dir
  Loop
  StatusBar = &quot;&quot;
End Sub
 
Thank you Justin!! I kept searching and found some code that got me started, but you have pointed out a piece that I was missing!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top