#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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 |
#3
|
|||
|
|||
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 |
#4
|
||||
|
||||
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 |
#5
|
|||
|
|||
Brilliant, thanks
|
#6
|
|||
|
|||
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? |
#7
|
||||
|
||||
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 |
#8
|
|||
|
|||
Thanks so much, I will try it out tomorrow.
|
#9
|
||||
|
||||
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 |
#10
|
||||
|
||||
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 |
#11
|
|||
|
|||
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 |
#12
|
|||
|
|||
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 |
#13
|
||||
|
||||
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 |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
change printer settings - page size not paper size | trevorc | Excel Programming | 4 | 07-20-2020 05:10 PM |
Change Page size | dita | Word VBA | 4 | 05-19-2020 07:04 PM |
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 font style and size in multiple documents | fitkhan | Word | 1 | 04-27-2011 09:49 PM |