Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 02-12-2016, 07:54 AM
Dretherix Dretherix is offline Copy, Paste, and Format Multiple Headings Windows 8 Copy, Paste, and Format Multiple Headings Office 2013
Novice
Copy, Paste, and Format Multiple Headings
 
Join Date: Feb 2016
Posts: 4
Dretherix is on a distinguished road
Default

So, I tried to edit something and forgot to click save, so it looks like I deleted my post. Here's the rewrite.

This is my first attempt to create a macro in Word, and I'm stuck. I'm trying to automate a tedious process where I use multiple Heading 1 (title), Heading 2 (author) and Heading 3's (date) to create a table of contents. I've tried using the build in ToC, but it doesn't allow for the specific customization that I need. Basically, I need to copy and paste the first H2 at the top of page, italicize it, put a colon after it, then copy and paste the first H1 after the colon, hyperlink it so that it goes to back to where it is located in the doc, add a space, then put H3 inside parentheses so that it allows follows the (Month Day, Year) format, and then do it all again for the next set.

Here is what it's supposed to look like:

Author : Title (February 12, 2016)

Here is what that is pulling from in the body:

Title (H1)
Author (H2)
12 Feb 2016 (H3)

I've cobbled together bits and pieces from this and other forums, but I'm a bit out of my depth. I've pasted below the parts that I can get to work, but it is pasting both the H1 and H2 twice at the top of the page, and I'm not even close to figuring out how to put them on the same line, italicize and hyperlink. I wish I could have included a better attempt. Any help is greatly appreciated.

Here is what I have so far:

Code:
Sub HeadingTest4()
'
' HeadingTest4 Macro
'
'
While Selection.Characters.Last.Next.Style = "Heading 1"
    Selection.MoveEnd Unit:=wdCharacter, Count:=1
  Wend
  Selection.MoveStart Unit:=wdCharacter, Count:=1
  Selection.Collapse Direction:=wdCollapseEnd
  With Selection.Find
    .ClearFormatting
    .Text = ""
    .MatchWildcards = False
    .Forward = True
    .Style = ActiveDocument.Styles("Heading 1")
    .Execute
    .ClearFormatting
  End With
    Selection.Find.Execute
    Selection.Copy
    Selection.MoveUp Unit:=wdWindow, Count:=1
    Selection.PasteAndFormat (wdListDontMerge)
    Selection.PasteAndFormat (wdFormatPlainText)
While Selection.Characters.Last.Next.Style = "Heading 2"
    Selection.MoveEnd Unit:=wdCharacter, Count:=1
  Wend
  Selection.MoveStart Unit:=wdCharacter, Count:=1
  Selection.Collapse Direction:=wdCollapseEnd
  With Selection.Find
    .ClearFormatting
    .Text = ""
    .MatchWildcards = False
    .Forward = True
    .Style = ActiveDocument.Styles("Heading 2")
    .Execute
    .ClearFormatting
  End With
    Selection.Find.Execute
    Selection.Copy
    Selection.MoveUp Unit:=wdWindow, Count:=1
    Selection.PasteAndFormat (wdListDontMerge)
    Selection.PasteAndFormat (wdFormatPlainText)
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy, Paste, and Format Multiple Headings Format when I copy and paste to a web site. stepz157 Word 2 06-04-2015 08:33 AM
Copy, Paste, and Format Multiple Headings Copy Paste Serial No to Excel in Text format linan123 Excel 1 05-02-2014 07:50 PM
Copy, Paste, and Format Multiple Headings Paste Special: Copy and Paste Formatting Only? tinfanide Word 6 03-06-2013 12:21 AM
Trying to find and copy all headings at the same time WaltR Word 7 08-21-2012 03:12 PM
Copy, Paste, and Format Multiple Headings Copy Paste ruins format korric Word 1 04-08-2012 05:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:20 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft