Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-24-2020, 06:38 PM
Steve_D Steve_D is offline Change page size for hundreds of documents Windows 7 32bit Change page size for hundreds of documents Office 2007
Advanced Beginner
Change page size for hundreds of documents
 
Join Date: Dec 2009
Posts: 59
Steve_D is on a distinguished road
Default Change page size for hundreds of documents


Hi
I know a bit about Word but am totally new to VBA, but I think it might help here.
I have 500+ Word documents that have been set up with Letter page size and I need to change them all to A4. Is there a way to do this with VBA?

I also need to change the footers in all the documents. I have previously set up a word macro to do this (one by one), but if this could also be done more efficiently in VBA, please let me know.

Is there a good resource where I can find this kind of information?

Cheers
Reply With Quote
  #2  
Old 08-24-2020, 07:56 PM
gmayor's Avatar
gmayor gmayor is offline Change page size for hundreds of documents Windows 10 Change page size for hundreds of documents Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You could probably use the custom process of https://www.gmayor.com/document_batch_processes.htm to make the changes, but you will have to modify your macro to work with it. There will inevitably be formatting changes, but without knowing what is in the documents it is impossible to be precise about what needs to change. The following will get you started.



Code:
Sub Resize(oDoc As Document)
    If oDoc.PageSetup.PaperSize = wdPaperLetter Then
        oDoc.PageSetup.PaperSize = wdPaperA4
    End If
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 08-24-2020, 08:37 PM
Steve_D Steve_D is offline Change page size for hundreds of documents Windows 7 32bit Change page size for hundreds of documents Office 2007
Advanced Beginner
Change page size for hundreds of documents
 
Join Date: Dec 2009
Posts: 59
Steve_D is on a distinguished road
Default

Thanks Graham,
Do you mean to add that code as a "user defined process" in your batch process add-on?
If not, how do I run it over a folder of files?
Cheers
Reply With Quote
  #4  
Old 08-24-2020, 10:34 PM
gmayor's Avatar
gmayor gmayor is offline Change page size for hundreds of documents Windows 10 Change page size for hundreds of documents Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Yes - call it from a user defined process. Try it on a folder with some copies of the documents so that you can see what problems it creates that need to be addressed.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 08-24-2020, 10:44 PM
Steve_D Steve_D is offline Change page size for hundreds of documents Windows 7 32bit Change page size for hundreds of documents Office 2007
Advanced Beginner
Change page size for hundreds of documents
 
Join Date: Dec 2009
Posts: 59
Steve_D is on a distinguished road
Default

Brilliant, thanks
Reply With Quote
  #6  
Old 08-25-2020, 12:05 AM
Steve_D Steve_D is offline Change page size for hundreds of documents Windows 7 32bit Change page size for hundreds of documents Office 2007
Advanced Beginner
Change page size for hundreds of documents
 
Join Date: Dec 2009
Posts: 59
Steve_D is on a distinguished road
Default

That worked well, Graham. Although it said the documents "were skipped or not fully processed " it did in fact change the page size on all of the test docs.
The only issue is that I have a mix of portrait and landscape docs and it changed the landscape ones to portrait.
Can the script be refined so it only changes the page size, not the orientation?
Reply With Quote
  #7  
Old 08-25-2020, 12:16 AM
gmayor's Avatar
gmayor gmayor is offline Change page size for hundreds of documents Windows 10 Change page size for hundreds of documents Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following should fix it. I will investigate the error log issue.

Code:
Sub Resize(oDoc As Document)
Dim lngOrient As Long
    lngOrient = oDoc.PageSetup.Orientation
    If oDoc.PageSetup.PaperSize = wdPaperLetter Then
        oDoc.PageSetup.PaperSize = wdPaperA4
        oDoc.PageSetup.Orientation = lngOrient
    End If
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #8  
Old 08-25-2020, 12:46 AM
Steve_D Steve_D is offline Change page size for hundreds of documents Windows 7 32bit Change page size for hundreds of documents Office 2007
Advanced Beginner
Change page size for hundreds of documents
 
Join Date: Dec 2009
Posts: 59
Steve_D is on a distinguished road
Default

Thanks so much, I will try it out tomorrow.
Reply With Quote
  #9  
Old 08-25-2020, 02:15 AM
Guessed's Avatar
Guessed Guessed is offline Change page size for hundreds of documents Windows 10 Change page size for hundreds of documents Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Page setup can vary across each section in a document. If you have documents which contain more than one section then you will need a macro that sets the page size & orientation for every section in each document.

Do you have section breaks in your docs?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #10  
Old 08-25-2020, 04:03 AM
gmayor's Avatar
gmayor gmayor is offline Change page size for hundreds of documents Windows 10 Change page size for hundreds of documents Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The issue of sections is of course something to bear in mind. As I said earlier, without access to the documents,it is impossible to be precise about what needs to change


I have fixed the log issue - the update is on my web site.Document Batch Processes
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #11  
Old 08-26-2020, 05:16 PM
Steve_D Steve_D is offline Change page size for hundreds of documents Windows 7 32bit Change page size for hundreds of documents Office 2007
Advanced Beginner
Change page size for hundreds of documents
 
Join Date: Dec 2009
Posts: 59
Steve_D is on a distinguished road
Default

Hi Graham
Unfortunately I got an error when running that new Resize macro. See screen shots attached. I'm running Office 2007 if that makes any difference.
Cheers
Attached Images
File Type: png Screenshot - 27_08_2020 , 10_13_02 AM.png (19.2 KB, 14 views)
File Type: png Screenshot - 27_08_2020 , 10_12_00 AM.png (10.0 KB, 14 views)
Reply With Quote
  #12  
Old 08-26-2020, 05:44 PM
Steve_D Steve_D is offline Change page size for hundreds of documents Windows 7 32bit Change page size for hundreds of documents Office 2007
Advanced Beginner
Change page size for hundreds of documents
 
Join Date: Dec 2009
Posts: 59
Steve_D is on a distinguished road
Default

Hi again,
Looking the docs, the macro worked up until the 4th out of 10 test files, then I got the bug. To be honest, at this point I am reconsidering the need to change from Letter to A4 as I think the files will still print OK. I think your batch processor could still be very useful for some other processes I need to make, e.g. find/replace. Thanks for your help so far!
Steve
Reply With Quote
  #13  
Old 08-26-2020, 06:54 PM
Guessed's Avatar
Guessed Guessed is offline Change page size for hundreds of documents Windows 10 Change page size for hundreds of documents Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

As I said earlier, if the document contains a section break then there could be more than one orientation in the document and you would need to treat each section individually. lngOrient would be undefined if there is a mix of orientation.

Code:
Sub Resize(oDoc As Document)
  Dim lngOrient As Long, aSect As Section
  For Each aSect In oDoc.Sections
    With aSect.PageSetup
      lngOrient = .Orientation
      If .PaperSize = wdPaperLetter Then
        .PaperSize = wdPaperA4
        .Orientation = lngOrient
      End If
    End With
  Next aSect
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change page size for hundreds of documents change printer settings - page size not paper size trevorc Excel Programming 4 07-20-2020 05:10 PM
Change page size for hundreds of documents Change Page size dita Word VBA 4 05-19-2020 07:04 PM
Change page size for hundreds of documents Hundreds of letters - print only the lead page on letterhead RookA1 Mail Merge 7 02-13-2018 11:08 AM
Change page size reducing both margins WizardDani Word 1 01-04-2018 06:41 AM
Change page size for hundreds of documents Change font style and size in multiple documents fitkhan Word 1 04-27-2011 09:49 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:12 AM.


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