Word macro to resize all .word documents in folder?

H1SOKA

New Member
Joined
Mar 17, 2016
Messages
38
Hey guys,

I need a macro to bulk resize all documents in a folder.

The dimensions are
15.24 x 22.86 cm.

Does anyone know how to do this? Thanks a lot!


 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
And when you do that, what's supposed to happen to margins, page headers/footers, etc. and any that doesn't fit the new page size (e.g. images, tabs)?

PS: 15.24 x 22.86 cm = 6in*9in
 
Upvote 0
And when you do that, what's supposed to happen to margins, page headers/footers, etc. and any that doesn't fit the new page size (e.g. images, tabs)?

PS: 15.24 x 22.86 cm = 6in*9in

Thanks for the question.

The content should be resized to fit the new page size. The content which does not fit the new page dimensions should be taken care of with additional pages because the pages are smaller in size. There are no images or tabs which need to be resized, only plain text.
 
Upvote 0
In that case, try:
Code:
Sub ReformatDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      With .PageSetup
        .PageHeight = InchesToPoints(9)
        .PageWidth = InchesToPoints(6)
      End With
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
 
Upvote 0
In that case, try:
Code:
Sub ReformatDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      With .PageSetup
        .PageHeight = InchesToPoints(9)
        .PageWidth = InchesToPoints(6)
      End With
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function

Hi There, thanks a lot for your response.

The code ends here and I get a compile error: Expected End Function
Function GetFolder() As String

It doesn't open a window to browse for a folder. Is there something I need to change?

Thanks again.
 
Upvote 0
Did you copy all the code - including the 'End Function' line? Your post suggests not.
 
Upvote 0
Did you copy all the code - including the 'End Function' line? Your post suggests not.

Here's the code that I used with the End Function line appended.

Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
If strFolder & "\" & strFile <> strDocNm Then
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
With .PageSetup
.PageHeight = InchesToPoints(9)
.PageWidth = InchesToPoints(6)
End With
.Close SaveChanges:=True
End With
End If
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function




Still not working? :confused:

I've tried everything and so far haven't a clue how to get it working.

Any help is appreciated!

Thank you
 
Upvote 0
Now you've omitted the first line of the code:
Sub ReformatDocuments()

The macro works just fine if you use ALL of it...
 
Upvote 0
Now you've omitted the first line of the code:
Sub ReformatDocuments()

The macro works just fine if you use ALL of it...

Wow I am amazed at my lack of attention to detail haha.

Your macro works perfect. Thanks a lot for your help!
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top