Pages in topic: < [1 2] | Merge and split MS Word files Thread poster: Samuel Murray
| What does the macro do? | Jan 20, 2013 |
Samuel Murray wrote: It would have to be integrated with MS Word itself, wouldn't it? Well, Automator is an OS X app, as you can see in the list of actions in the screenshot above. MS provided almost 100 actions for MS Office aline, there are many more, and you can make/record them yourself. Splitting a merged file is still the problem. What do those macros do? If it's not too far-reaching, maybe merging the files, run the macros, translate the one merged file in your favourite CAT tool, create a new project with the original files, and "pretranslate" the individual files (maybe with a lower match percentage than 100), will do. Cheers, Hans | | | Samuel Murray Netherlands Local time: 03:08 Member (2006) English to Afrikaans + ... TOPIC STARTER
Meta Arkadia wrote: If it's not too far-reaching, maybe merging the files, run the macros, translate the one merged file in your favourite CAT tool, create a new project with the original files, and "pretranslate" the individual files (maybe with a lower match percentage than 100), will do. The original files are non-standard partially translated uncleaned RTF files in DOC format, so I can't use a CAT tool to merge/split them. | | |
Samuel Murray wrote: The original files are non-standard partially translated uncleaned RTF files in DOC format, so I can't use a CAT tool to merge/split them. That's not what I had in mind. Since merging is not the problem (splitting is): - merge the files - run your macros - import and translate the resulting 1 document in your CAT tool - save the TM for that project Followed by: - import all your 100 original files in you CAT tool - "attach" your Project TM (and only that resource) - run a "pretranslate" (DV Speak) and accept only 100% matches (or say 90-100%, depending on your macros), and tell your CAT tool to insert the source text in other cases - sit and relax I realise there can be various problems with that approach, but they depend mainly on the macros you ran and the document structure. Cheers, Hans
[Edited at 2013-01-21 00:32 GMT] | | | P Forgas Brazil Local time: 23:08 Portuguese to Spanish + ... Master document? | Jan 21, 2013 |
You could automate the adding process. I really don't know how. P. | |
|
|
Samuel Murray Netherlands Local time: 03:08 Member (2006) English to Afrikaans + ... TOPIC STARTER Automating the adding process | Jan 21, 2013 |
P Forgas wrote: You could automate the adding process. I was able to automate the merging and splitting, using AutoIt, but because of the fact that I can't store MS Word's clipboard as a variable, and because I have to perform find/replace using MS Word's own dialog boxes, merging 100 files takes 10 minutes, and splitting it takes 45 minutes. That is far from ideal. A macro would be able to cut that time by a lot, because it would not need to call the dialogs and would (in principle) be able to store the MS Word clipboard as a variable. | | | Rolf Keller Germany Local time: 03:08 English to German Splitting & merging is easy - but only on first glance | Jan 21, 2013 |
Samuel Murray wrote: I was able to automate the merging and splitting As I said earlier, there is no straightforward way to split/merge via any script or macro that works under all circumstances. You would have to change all template names temporarily in order to avoid conflicts. You would have to cope with the Sections feature. You would have to cope with settings like "Apply this to the whole document" (which actually should apply to a part of the big file only). You would have to cope with different headers/footers, with picture anchors, ... A macro would be able to cut that time by a lot, because it would not need to call the dialogs and would (in principle) be able to store the MS Word clipboard as a variable. An even faster solution is a software written by you in the free Visual Studio .NET Express. You need an Office adapter, though, e. g. VSTO (from MS, non-free(?)) or NetOffice (free, http://netoffice.codeplex.com/). This enables you to do all things that could be done via VBA, but without a slow script/macro.
[Bearbeitet am 2013-01-21 13:24 GMT] | | | | Here you go... | Jan 23, 2013 |
Below you will find two Word macros. The first one (based on the code Tony posted above) merges all Word files in a single directory into one file and the second one puts them back. These are very much beta versions and you run them entirely at your own risk. In particular, there is very little error checking so, if you do something silly, you will probably regret it. There is one known bug in that it seems to add an extra page break to the end of some files. I'm looking into that.... See more Below you will find two Word macros. The first one (based on the code Tony posted above) merges all Word files in a single directory into one file and the second one puts them back. These are very much beta versions and you run them entirely at your own risk. In particular, there is very little error checking so, if you do something silly, you will probably regret it. There is one known bug in that it seems to add an extra page break to the end of some files. I'm looking into that... I suggest you: 1) Copy all the files you want to merge into a work directory 2) Open Word with a new empty document. Make sure no other documents are open. 3) Run ConcatenateAllWordFiles. When it prompts for a directory, select the one you created in step 1. 4) It should then create a document called __MERGED__DOCS__.doc in the same directory. 5) Make your changes to the merged docs. 6) Run SplitAllWordFiles in the merged document. Make sure no other documents are open. NOTE: This will overwrite/recreate the original files in the original directory even if you have moved/renamed them in the meantime. Let me know how you get on with it. Sub ConcatenateAllWordFiles() 'Combines all Word files in a directory into a single file called __MERGED__DOCS__.doc 'RUN THIS MACRO IN A NEW, EMPTY DOCUMENT 'This macro was written by Terry Richards unless it blows up and does ugly things 'to your computer, in which case I don't know who wrote it. 'It is supplied "as is" and it is entirely your own responsibility to confirm that 'it is adequate and suitable for your purposes. You run it entirely at your own risk. Dim master, path As String 'Prompt for the directory that contains the source files Dim dlgOpen As FileDialog Set dlgOpen = Application.FileDialog(FileDialogType:=msoFileDialogFolderPicker) 'If the user didn't press cancel, go ahead and search this directory If dlgOpen.Show 0 Then 'Save the selected path, generate the filename for the merged document and create it empty path = dlgOpen.SelectedItems(1) master = path + "\__MERGED__DOCS__.doc" ActiveDocument.SaveAs (master) 'Now search all files in this directory With Application.FileSearch .NewSearch .LookIn = path .SearchSubFolders = False .FileName = "*.*" .Execute 'For each file For i = 1 To .FoundFiles.Count 'Is it a Word file? You can add other file types here (like RTF) If Right(.FoundFiles(i), 4) = ".doc" Or Right(.FoundFiles(i), 5) = ".docx" Then 'There are at least 2 files to be ignored - 'the one we are creating and any Word work file(s) If .FoundFiles(i) master And InStr(.FoundFiles(i), "~$") = 0 Then 'If we get this far, we have found a Word doc to merge into the new file 'So open it Documents.Open FileName:=.FoundFiles(i), _ ConfirmConversions:=False, ReadOnly:=True, AddToRecentFiles:=False, _ PasswordDocument:="", PasswordTemplate:="", Revert:=False, _ WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _ wdOpenFormatAuto 'Save the file name, copy the entire document to the clipboard and close it current = ActiveDocument.Name Selection.WholeStory Selection.Copy Documents(current).Close 'Insert a page break, the special magic cookie, and the full file name Documents(master).Activate Selection.InsertAfter ("__%%FILE%%__: ") Selection.EndKey Unit:=wdLine Selection.InsertAfter (path) Selection.EndKey Unit:=wdLine Selection.InsertAfter ("\") Selection.EndKey Unit:=wdLine Selection.InsertAfter (current) Selection.EndKey Unit:=wdLine Selection.InsertBreak (wdPageBreak) Selection.EndKey Unit:=wdLine 'Paste the clipboard contents Selection.Paste Selection.EndKey Unit:=wdLine Selection.InsertBreak (wdPageBreak) End If End If Next i 'All documents processed, save the merge file ActiveDocument.Save End With End If End Sub Sub SplitAllWordFiles() 'Splits out a merge file created by ConcatenateAllWordFiles 'RUN THIS MACRO IN __MERGED__DOCS__.doc 'This macro was written by Terry Richards unless it blows up and does ugly things 'to your computer, in which case I don't know who wrote it. 'It is supplied "as is" and it is entirely your own responsibility to confirm that 'it is adequate and suitable for your purposes. You run it entirely at your own risk. Dim FileName As String Dim Content As Range 'We work from the end of the document backwards 'So first move to the end Selection.EndKey Unit:=wdStory Selection.Find.ClearFormatting 'Set up a search for the magic cookie With Selection.Find .Text = "__%%FILE%%__: " .Replacement.Text = "" .Forward = False .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False 'Search while there is still one found Do While .Execute() = True 'Find the file name relative to the magic cookie and save it Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.MoveEnd (wdParagraph) Selection.MoveEnd Unit:=wdCharacter, Count:=-1 FileName = Selection 'Delete the magic cookie line Selection.Expand (wdParagraph) Selection.Delete 'Select from here to the end of the document 'and cut the content to the clipboard Selection.MoveDown Unit:=wdLine, Count:=1 Selection.EndKey Unit:=wdStory, Extend:=wdExtend Selection.Cut 'Delete the extra page Selection.TypeBackspace 'Create a new empty document, paste the content into it, 'save it with the original file name and close it. 'NOTE: This will overwrite the original files in their original directory 'This would be a good time to have a backup... Documents.Add DocumentType:=wdNewBlankDocument Selection.Paste ActiveDocument.SaveAs FileName:=FileName, FileFormat:= _ wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _ True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _ False, SaveNativePictureFormat:=False, SaveFormsData:=False, _ SaveAsAOCELetter:=False ActiveDocument.Close Loop End With End Sub ▲ Collapse | |
|
|
Code is scrambled | Jan 24, 2013 |
Apparantly the board software has scrambled my code. If you want a copy, send me a PM and I will send it in a txt file. | | | Samuel Murray Netherlands Local time: 03:08 Member (2006) English to Afrikaans + ... TOPIC STARTER Terry's macros | Jan 30, 2013 |
Terry Richards wrote: Apparantly the board software has scrambled my code. The pair of macros work nicely, thanks. It adds a line break at the top of each file and two line breaks at the bottom of each file, but other than that it works fine. The output folder must exist beforehand. The macros are here: http://wiki.proz.com/wiki/index.php/Merge_and_split_doc_files | | | This macro no longer seems to work in MS Word 2010 | Nov 26, 2014 |
Hi, I am not very advanced when it comes to macros, but when I try to run this macro, it tells me that "application.filesearch" isn't compatible with my version of Word. Is there an updated version of this macro at all? | | | Use "FileSystemObject" for Office 2010 | Nov 27, 2014 |
R/T: you have to use FileSystemObject in Office 2010, a la: Code:
|
Sub MyFileSystemObject(path)
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
'-- Get each folder path
For Each folder In fso.GetFolder(path).SubFolders
'-- Call the function ... See moreR/T: you have to use FileSystemObject in Office 2010, a la: Code:
|
Sub MyFileSystemObject(path)
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
'-- Get each folder path
For Each folder In fso.GetFolder(path).SubFolders
'-- Call the function recursively to search within sub-folders
MyFileSystemObject folder.path
Next
'-- Get the file path for each file
For Each file In fso.GetFolder(path).Files
Debug.Print file.Path
Next
End Sub
|
|
I would wager there is an Office 2010-compatible version somewhere on the Net already, so do a little searching. I will look too and report back if I find anything. If not, I'll work on updating the macro myself. MLG4035 ▲ Collapse | |
|
FileSystemObject version of macro | Nov 27, 2014 |
Hi Michael, Thank you for your quick reply! I have taken a look around what is available, but can't see a suitable revised macro at all, while my own scripting prowess is unfortunately not currently good enough to re-purpose the existing macro using the FileSystemObject instead. It would be fantastic to have a new version posted here for others to use! | | | Pages in topic: < [1 2] | | To report site rules violations or get help, contact a site moderator: You can also contact site staff by submitting a support request » Merge and split MS Word files TM-Town | Manage your TMs and Terms ... and boost your translation business
Are you ready for something fresh in the industry? TM-Town is a unique new site for you -- the freelance translator -- to store, manage and share translation memories (TMs) and glossaries...and potentially meet new clients on the basis of your prior work.
More info » |
| Trados Studio 2022 Freelance | The leading translation software used by over 270,000 translators.
Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop
and cloud solution, empowering you to work in the most efficient and cost-effective way.
More info » |
|
| | | | X Sign in to your ProZ.com account... | | | | |
|
You can request verification for native languages by completing a simple application that takes only a couple of minutes.
Review native language verification applications submitted by your peers. Reviewing applications can be fun and only takes a few minutes.
View applications
|