#1
|
|||
|
|||
Split Multiple Word Documents by Bookmark
Hello all,
I'm trying to split multiple Word documents into separate documents using the document bookmarks. I found a previously posted macro that works great for doing this. However, I'm running into an issue with the code as it relates to my project. I'm trying to have the VBA loop across ~300 documents where all have the same bookmark names and are all in the same folder. It looks like the code loops across documents based on the "StrNm = Dir()" line. However, the newly saved folders are based on bookmark names, which are the same across all documents. It looks like this is causing an error and the marco to stop after the first document. I want to adjust the code in two ways to (1) deal with the bookmark naming issue and (b) create new documents within the same folder (aka not create new folders for each new document. For example, the new documents should be roughly "[docname]_[bookmarkname].doc". How might I accomplish this? Thanks in advance for any assistance someone can provide! |
#2
|
||||
|
||||
Can you post a few sample documents so we can test the code on what you actually have. The code you are using looks like it makes assumptions on where bookmarks start and end and deals with how many of the bookmarks overlap. Your documents might not follow the same patterns that it is coded for.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Apologies, but I can't share any of the text files. However, the bookmarks are all in the proper place in each file. No overlap across bookmarks either. Where one ends, the next starts in all of the documents.
The problem is that the bookmarks have the same name in each file (not my doing). This keeps the script from working for more than one document at a time. |
#4
|
||||
|
||||
Are all your files .doc or something else such as .docx?
This code (as written) only returns .doc files StrNm = Dir(StrPth & "\*.doc", vbNormal)
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Yes, all files are in .doc format (I converted them with some other VBA code). Again, the ONLY issue I am dealing with is the bookmarks have the same names across files.
Here is what's happening: when I run the code, it creates folders with the files split based on the bookmarks in it for the *FIRST* document. Then, it gives me an error and cannot create folders with files in it it for the second document because said folders/files already exist. As mentioned, all the bookmarks have the same name and that's what used to name the folders/files. I suspect all I need is an additional line of code to adjust the name of the folders/files. For example, it would work if the saved files end up being "[originalfilename]_[bookmarkname].doc" rather than what it is right now, "[bookmarkname].doc". That would solve the issue. However, I couldn't get anything like that to work with my code, so I'm reaching out on here. |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA to split Word document into multiple documents | Shelley Lou | Word VBA | 1 | 02-24-2021 07:11 AM |
split word document based on bookmarks with each new document title of the bookmark | megatronixs | Word VBA | 9 | 09-05-2020 02:29 PM |
Macro to Split Documents | Gingerbreadgrl | Word VBA | 4 | 09-02-2019 03:18 PM |
Mail Merge - split merged documents and rename each split document based on text in header | FuriousD | Word VBA | 1 | 05-12-2019 04:06 AM |
Split one Word Document into Multiple PDFs | VieraOfficeUser | Word | 3 | 07-30-2014 10:58 PM |