| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

09-16-09, 07:30
|
|
Registered User
|
|
Join Date: May 2009
Posts: 10
|
|
VB Script for Word Doc creation
|
|
Hi All
Am in urgent need for a VB script that can create word files from an existing document.
Ex: i have about 100 pages in a document, which i need to create individual Word files for each page, with a name on each file.
Can any one please help me out here.....
Thanks in Advance.
Srini
|
|

09-16-09, 08:50
|
|
Registered User
|
|
Join Date: May 2009
Posts: 257
|
|
|
|

09-17-09, 00:40
|
|
Registered User
|
|
Join Date: May 2009
Posts: 10
|
|
|
|
Hi Ax, thanks for sending this link. Am not quite sure, how to do the delimiter in the word file. Can you help me out with that.
** i added the code in a new module, post that am stuck in proceeding further
|
|

09-17-09, 10:30
|
|
Registered User
|
|
Join Date: May 2009
Posts: 257
|
|
The delimiter would be whatever text you wanted to use as a splitting point for the files. But do note that this delimiter should be unique to the document, in that it would not be present anywhere else in the document. If this is a document created from a [mail] merge, see the second link.
It's hard for me to assist you without knowing what's in the document. How was this document created? Does it have section breaks or bookmarks?
|
|

09-17-09, 12:30
|
|
Registered User
|
|
Join Date: May 2009
Posts: 257
|
|
I coded the following method, it should work for you:
Code:
Sub SplitDocument()
Dim iCount As Integer, i As Integer, DocName As String, DocPath As String
iCount = BuiltInDocumentProperties(wdPropertyPages)
DocName = Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1)
DocPath = ActiveDocument.Path
For i = 1 To iCount
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=i
ActiveDocument.Bookmarks("\Page").Range.Copy
Documents.Add.Content.Paste
ActiveDocument.Bookmarks("\EndOfDoc").Select
If i <> iCount Then Selection.TypeBackspace ' Remove page break on all but last page
ActiveDocument.SaveAs Path & "\" & DocName & " Page " & i
ActiveDocument.Close
Next
End Sub
You can see how it works by stepping through it and viewing the document. If you need to name them differently, I'm sure that won't be too difficult. It saves the files in the same directory as the document you are splitting, but you can change that easily enough as well.
Ax
|
|

10-08-09, 04:50
|
|
Registered User
|
|
Join Date: May 2009
Posts: 10
|
|
|
Hi Ax
Hi
thanks for your responses. I have been traveling for the last couple of weeks so i couldnt revert to you. thanks a ton for your help.
Am still encountered with a problem, when i put ur code in a module, i get a complier Error in line = incount.
Also can you help me by explaning, how the process of this works. i;e, from mail merge to splitting them in individual docs.
Thanks again Ax, appreciate your help to me.
Regards
Srini
|
|

10-08-09, 04:53
|
|
Registered User
|
|
Join Date: May 2009
Posts: 10
|
|
the complie error that i get from your code is in line 3 which starts at iCount = BuiltInDocumentProperties.
|
|

10-08-09, 05:16
|
|
Registered User
|
|
Join Date: May 2009
Posts: 10
|
|
Ax, now i could manage myself to split the document, but the document after split lies in one document with mupltiple pages. Can you guide me as to how can i save those pages into individual files?
|
|

10-08-09, 11:55
|
|
Registered User
|
|
Join Date: May 2009
Posts: 257
|
|
The code I posted will save them into individual files. What is the error that you are receiving? Try changing the line to the following:
Code:
iCount = ActiveDocument.BuiltInDocumentProperties("Number of Pages")
Ax
|
|

10-09-09, 00:24
|
|
Registered User
|
|
Join Date: May 2009
Posts: 10
|
|
Hi Ax,
Thanks for the code, now able to save the document in individual filese
but there is a complie error that i get in the below line
ActiveDocument.SaveAs Path & "\" & DocName & " Page " & i
as with reference to PATH. Not sure what to do now?
Also when i run the code to save the files in individual files, i get all 100 pages in each individual file, can you help me solve this?
|
|

10-09-09, 09:17
|
|
Registered User
|
|
Join Date: May 2009
Posts: 257
|
|
My bad, that line should be:
Code:
ActiveDocument.SaveAs DocPath & "\" & DocName & " Page " & i
So the code should be:
Code:
Sub SplitDocument()
Dim iCount As Integer, i As Integer, DocName As String, DocPath As String
iCount = ActiveDocument.BuiltInDocumentProperties("Number of Pages")
DocName = Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1)
DocPath = ActiveDocument.Path
For i = 1 To iCount
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=i
ActiveDocument.Bookmarks("\Page").Range.Copy
Documents.Add.Content.Paste
ActiveDocument.Bookmarks("\EndOfDoc").Select
If i <> iCount Then Selection.TypeBackspace ' Remove page break on all but last page
ActiveDocument.SaveAs DocPath & "\" & DocName & " Page " & i
ActiveDocument.Close
Next
End Sub
Ax
|
|

10-12-09, 01:21
|
|
Registered User
|
|
Join Date: May 2009
Posts: 10
|
|
this is awesome  just how i wanted it to be. Thank you so much Ax..
am delighted with what i could accomplish with your code.
Srini
|
|

10-13-09, 05:02
|
|
Registered User
|
|
Join Date: May 2009
Posts: 10
|
|
Hi Ax, could you also help me in telling me which code would help me save the files in the name i want?
|
|

10-15-09, 13:59
|
|
Registered User
|
|
Join Date: May 2009
Posts: 257
|
|
The following line saves the files, just change it to what you want the name to be:
Code:
ActiveDocument.SaveAs DocPath & "\" & DocName & " Page " & i
Ax
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|