Book module

Share your favorite tips, workarounds and shortcuts for theWord
Faith
Posts: 5
Joined: Sun Sep 12, 2010 1:49 pm

Re: Book module

Post by Faith »

Hi. miken

I am determined to sort out how to do it.

Have found a few half solutions but have to still work on them.

Have been very busy and not able to work on it at the moment.

As soon as I find a solution I will let you know.

:D


God bless -
Faith
miken
Posts: 89
Joined: Thu Sep 02, 2010 4:52 pm

Re: Book module

Post by miken »

Hey Faith
Thanks for your rapid answer.
I'm glad I bumped this - even if you were already 'on it' - just to get the response!
After all - we all know that 'Faith is what gets the job done!' - isn't that right?
Hope it goes well for you: - I'm sure you will have other grateful end-users :)

Particularly since you wrote:
But I have NO knowledge of macros . Just know how to paste the info in.
So - if you get stuck - pray for wisdom!... - and practically speaking - there are other forums out there with very experienced people, besides on here, who may have a solution to a particular question.

I'm looking forward to news, when it comes. :D

Blessings!
miken
csterg
Site Admin
Posts: 8627
Joined: Tue Aug 29, 2006 3:09 pm
Location: Corfu, Greece
Contact:

Re: Book module

Post by csterg »

Do you have the sample macro(s) I have posted? (I think i posted them)
Costas
Faith
Posts: 5
Joined: Sun Sep 12, 2010 1:49 pm

Re: Book module

Post by Faith »

Hi miken

Well after seeing your post, I decided to do something about it.
Still don"t know how to make a macro from scratch but by some miracle I managed to get us one to use.
Only by faith.

I have taken two macros that I found at vbaexpress.co.za (submitted by Tinbendr) and joined them.
The following macro will split a large word document by headings in to smaller documents.

It will look for 'Heading 1' (which is a style name) no matter what the font is.
Every new file will be named exactly like the headings that are chosen by you using text in “Heading 1” style.

The result is now that when the output files are saved they will be marked with a number in the front keeping it in the same order that was in the original document.
The documents will be named as follows :

First file- 2 _ Aging Wisdom.doc
Second file- 3 _ A. What Is Aging today.doc
Third file- 4 _ B. The Seasons of Aging today.doc

What to do:

1. Go to all the questions or chapters that you want in separate documents and then change them to “Heading 1”

2. The only difference is you have to put a word at the bottom of your document eg. END and also make it a “header 1”.

3. Run the macro named (ParseFileByHeadingSaveDoc) for .doc

4. Or named (ParseFileByHeadingSaveRTF) if you want rtf.





This is the code to save in .doc

VBA:

Code: Select all

Sub ParseFileByHeadingSaveDoc() 
 
Dim aDoc As Document 
Dim bDoc As Document 
Dim Rng As Range 
Dim Rng1 As Range 
Dim Rng2 As Range 
Dim Counter As Long 
Dim Ans$ 
 
 'Ans$ = InputBox("Enter Filename", "Incremental number added")
 'If Ans$ <> "" Then
 
Set aDoc = ActiveDocument 
Set Rng1 = aDoc.Range 
Set Rng2 = Rng1.Duplicate 
 
Do 
    With Rng1.Find 
        .ClearFormatting 
        .MatchWildcards = False 
        .Forward = True 
        .Format = True 
        .Style = "Heading 1" 
        .Execute 
    End With 
     
    If Rng1.Find.Found Then 
        Ans$ = Rng1.Text 
        Counter = Counter + 1 
        Rng2.Start = Rng1.End + 1 
        With Rng2.Find 
            .ClearFormatting 
            .MatchWildcards = False 
            .Forward = True 
            .Format = True 
            .Style = "Heading 1" 
            .Execute 
        End With 
         
        If Rng2.Find.Found Then 
            Rng2.Select 
            Rng2.Collapse wdCollapseEnd 
            Rng2.MoveEnd wdParagraph, -1 
            Set Rng = aDoc.Range(Rng1.Start, Rng2.End) 
            Set bDoc = Documents.Add 
            bDoc.Content.FormattedText = Rng 
             
            If Ans$ <> "" Then 
                bDoc.SaveAs Counter + 1 & " _ " & Left(Ans$, Len(Ans$) - 2) & ".doc", wdFormatDocument 
                 'bDoc.SaveAs Ans$ & Counter, wdFormatDocument
                bDoc.Close 
            Else 
                 'This collects from the last Heading 1
                 'to the end of the document.
                If Rng2.End < aDoc.Range.End Then 
                    Set bDoc = Documents.Add 
                    Rng2.Collapse wdCollapseEnd 
                    Rng2.MoveEnd wdParagraph, -2 
                    Set Rng = aDoc.Range(Rng2.Start, aDoc.Range.End) 
                    bDoc.Content.FormattedText = Rng 
                     
                    If Ans$ <> "" Then 
                        bDoc.SaveAs Counter + 1 & " _ " & Left(Ans$, Len(Ans$) - 2) & ".doc", wdFormatDocument 
                         'bDoc.SaveAs Ans$ & Counter, wdFormatDocument
                        bDoc.Close 
                    End If 
                End If 
            End If 
        End If 
    End If 
     
Loop Until Not Rng1.Find.Found 
 
 'This is closing End If from Ans$
 
End Sub 

Please note that the Module number will change if you add to your main Template for Microsoft Word.
Which I have Done.

Other choices:
1. If you run (ParseFileByHeading) the documents will be named as follows:

Aging Wisdom.doc
A. What Is Aging today.doc
B. The Seasons of Aging today.doc

2. When you run (ParseFileByHeadingNumbers) a macro input box will open and you will have to type something as my file name. Which will result that the separate files are named according to what you put in.

I put in Study_ (you have to at least put in one letter or number for it to work)

Study-1.doc
Study_2.doc
Study_3.doc

The other 3 Macros are in the Sample Supplied.

Tried to also explain with an image:

A very helpful program to copy text form different programs or sites with out you scrolling down and copy and paste is yourself.
That is the Hypersnap function

http://www.hyperionics.com/index.asp .
it has a trial version and just leave a evaluation mark in places after the trial.

Always make a copy of your document before you run the macro for safety .

I tried it using Office 2007 and 2010


God Bless

Faith
Attachments
Sample Macro.zip
Sample has the 4 Different macros in
(194.58 KiB) Downloaded 362 times
Last edited by Faith on Sun Sep 26, 2010 11:18 am, edited 2 times in total.
Faith
Posts: 5
Joined: Sun Sep 12, 2010 1:49 pm

Re: Book module

Post by Faith »

csterg wrote:Do you have the sample macro(s) I have posted? (I think i posted them)
Costas

Yes you did send me one. Thank you.

Sorry for not thanking you earlier.

But it did not work for me.

I have posted the one that is working for me now


God Bless

Faith
miken
Posts: 89
Joined: Thu Sep 02, 2010 4:52 pm

Re: Book module

Post by miken »

Hey, Faith!
I look forward to trying this. As I wrote - I am not a macro writer or user - though I have some (very) small knowledge of logic and old-fashioned 'Basic'... - so I can read and understand the posting.

As I also wrote: "After all - we all know that 'Faith is what gets the job done!' - isn't that right?
Hope it goes well for you" - so my 'hope' did turn to 'Faith' - and 'Faith' produced:
as the scriptures tell us in the Word: that 'faith is the substance of things hoped for...' 8)

Thank you for responding! So - those of us with no knowledge... have we been 'saved' by Faith ? - :lol:
Now I leave things to the experts out there - who may or may not now add, tweak, encourage, use, share their own...
(All by grace, of course!)

God bless
Mike (miken)
Post Reply