Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2016, 03:11 PM
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 Copy, Paste, and Format Multiple Headings


This is my first time trying to create a macro and I'm stuck. I'm trying to automate a tedious process where I have to pull a series of Heading 1 (title), Heading 2 (author), and Heading 3's (date) and create a table of contents. I've tried using the ToC in Word, but I can't customize it to look exactly like I need. Basically, I need to copy and paste H2 at the top of the page, make it italicized, put a colon after it, copy and paste H1, hyperlink it so it takes you to H1 in the doc, then copy and paste H3 in paratheses so that it always reads in the (Month Day, Year) format. Then I need it to go to the next set and do the same thing, but paste it underneath the first one.

Here is an example of what it would look like:

Author: Title (February 11, 2016)

And the headings in the body look like:

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

I've tried to cobble together bits and pieces from other forums and ended up with the below. However, it is pasting H1 and H2 twice at the top of the page, and I'm not even getting close to italicizing and hyperlinking. So, I realize that I'm very far away and I would have liked to have included a better attempt, but I'm a bit out of my depth. Any help would be greatly appreciated.
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

Last edited by Dretherix; 02-11-2016 at 03:56 PM. Reason: Added code tags & formatting
Reply With Quote
  #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
  #3  
Old 02-12-2016, 08:26 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 Copy, Paste, and Format Multiple Headings

I tried to make an edit to my earlier post with the same title, but it looks like I deleted it entirely. Not sure exactly what happened, but apologies. Here is my rewrite.

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

Here is what the first one should look like:

Author: Title (February 12, 2016)

And here is what that is pulling from:

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

I've cobbled together bits and pieces from this and other forums and pasted what I have below. However, it pastes both H1 and H2 twice, and I'm not even close to figuring out how to put them on the same line, italicize and hyperlink. I wish I had a better attempt to include, but I'm struggling. Any help would be 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
Reply



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 05:22 AM.


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