Results 1 to 14 of 14
  1. #1
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Create Title Page (VBA 6.3/Word 2003)

    I need to create a macro in VBA 6.3 that takes the title and author of an paper and then creates a title page for that paper. Unfortunately, I'm a bit stumped. It seems so simple.

    I'm thinking that I can go in and insert a section break, copy everything prior to the section break, take that information to the top of the file and insert and reformat it there. Any suggestions on procedures to do this?

    (Yes, I know, dumb question. [img]/forums/images/smilies/smile.gif[/img])

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    Do you want to do this with already existing documents? For new documents, it would be easier to create and use a template that already has a title page.

    And do you want to use the Author and Title as specified in the File | Properties dialog?

  3. #3
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    It's an already existing document. The intented use is for processing academic papers with multiple sources--profs, students, etc.

    The style for the Heading is consistant. "Head1" is the style for the title and the style for the author is "AuthorName1" in every document that it would be used on.

    Most of the documents I checked didn't have the correct informtion listed in the Document Properties. Perhaps it could be transferred? Or could I just grab the information contained in the styles I listed?

    Thanks for the help, BTW. [img]/forums/images/smilies/smile.gif[/img]

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    Could you attach a small sample document? You can strip away most of the document, and replace real information with dummy information. Leave enough for us to get an idea of what you're working with.

  5. #5
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    Here is a small sample file.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    Try this macro:

    Sub CreateTitlePage()
    Application.ScreenUpdating = False
    Selection.HomeKey Unit:=wdStory
    Selection.InsertBreak Type:=wdSectionBreakNextPage
    Selection.HomeKey Unit:=wdStory
    Selection.InsertParagraph
    Selection.HomeKey Unit:=wdStory
    ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldStyleRef, Text:="_AuthorName1"
    Selection.Paragraphs(1).Style = ActiveDocument.Styles("_CoverAuthor")
    Selection.TypeParagraph
    ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldStyleRef, Text:="_Head1"
    Selection.Paragraphs(1).Style = ActiveDocument.Styles("_COVERTITLE")
    Selection.Paragraphs(1).Range.Relocate wdRelocateUp
    Application.ScreenUpdating = True
    End Sub

  7. #7
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    It appears to work well with my first couple of tests.

    Thanks for much for your help! You're a lifesaver.

    Can you do one other thing for me??? I need a good book on this version of VBA. I don't have any reference books in house. I'd like to recommend one for my boss to buy us.

    Thanks Again!

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    I don't have any Word VBA books myself, you might do a search in this forum and in the Word forum for word vba books. Perhaps others will come up with a specific suggestion.

    You'll find lots of useful code here in Woody's Lounge, and in Word MVP FAQ - Macros/VBA.

  9. #9
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    Ok, I had to go and get complicated. I inserted a form that would allow me to choose whether it was a profs article and a student article (which uses different styles). I thought I had it right, but I'm not getting the right result with the student option.

    Can anyone tell me where I muffed the code??? Here is the demo file.

    I'll post the code.

    I think it is when I call the "_Head2-Comments" style reference, but I can't pinpoint it exactly.

  10. #10
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    Long code fragment (over 4,000 characters) moved to attachment by HansV

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    A general remark: you can configure the option buttons in a loop:

    Rem *** Configure Option Buttons ***
    For x = 0 To 5
    With myform.Controls("optChoice" & (x + 1))
    If cCover(x) <> "" Then
    .Visible = True
    .Caption = cCoverText(x)
    Else
    .Visible = False
    End If
    End With
    Next x

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    I was running into similar problems when I wrote the original code. This was the reason for placing the fields in reversed order, then moving the second one up - it worked for the demo document. It seems that STYLEREF doesn't work dependably if the text referred to is in another section. Try replacing

    Selection.InsertBreak Type:=wdSectionBreakNextPage

    with

    Selection.InsertBreak Type:=wdPageBreak

  13. #13
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    That does indeed look much more elegant.

    I'm certainly learning a lot here.

  14. #14
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: Create Title Page (VBA 6.3/Word 2003)

    It works perfectly.

    Thanks Again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •