Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-31-2017, 01:21 PM
Charles Kenyon Charles Kenyon is offline applying heading style within paragraph using macro Windows 10 applying heading style within paragraph using macro Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,581
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Neither site contains any virus. These are old web pages and have been used safely for many years. What led you to believe that either was infected?

Do you understand the concept of the Style Separator? If not, you need to learn it.

The macro recorder is often unable to reproduce things that you do.


If your heading styles are "linked," attempting to apply the style to selected text is going to apply a poor-relation to that style, a quasi-character style, to the text.

What, exactly, step-by-step, is it you want your macro to do?
Why? What do you hope to accomplish by doing this?
Reply With Quote
  #2  
Old 08-21-2017, 07:41 AM
cheech1981 cheech1981 is offline applying heading style within paragraph using macro Windows 7 64bit applying heading style within paragraph using macro Office 2010 64bit
Advanced Beginner
applying heading style within paragraph using macro
 
Join Date: Nov 2011
Location: New Jersey, USA
Posts: 77
cheech1981 is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
Neither site contains any virus. These are old web pages and have been used safely for many years. What led you to believe that either was infected?
Sorry Charles--it was very odd. I clicked on the link my antispyware program gave me a warning message. Then, when I tried to replicate the issue, I had no issue. Not sure what the problem was, but maybe I already had something. I just ran a clean just to be safe but, like you said, I'm sure it wasn't your site, and I apologize for the misunderstanding.

Quote:
Originally Posted by Charles Kenyon View Post
Do you understand the concept of the Style Separator? If not, you need to learn it.
I can successfully create a heading style at the beginning of the paragraph (e.g., Heading 3) while maintaining another style for the rest of the paragraph (e.g., Body Text). I would like to do this through a macro though, rather than doing it manually.

Quote:
Originally Posted by Charles Kenyon View Post
The macro recorder is often unable to reproduce things that you do.
If your heading styles are "linked," attempting to apply the style to selected text is going to apply a poor-relation to that style, a quasi-character style, to the text.

What, exactly, step-by-step, is it you want your macro to do?
Why? What do you hope to accomplish by doing this?
I format documents that have a freestanding, flush-left heading style, and, sometimes, those headings must be changed to a run-in heading at the beginning of the paragraph below (think changing an APA 2 subheading to an APA 3 subheading). I can just do this manually if it is a few of them, but often I have to do it 50 times or so in a document. So I have set up a macro that does this, but the recorder does not seem to be recording the action of applying the Heading 3 style to the first bit of text.

I am pasting the current macro code below. Before running the macro, the user would select the freestanding heading (and any white space to the right of that heading). The macro places a period at the end of that text, brings the following paragraph up to join it, and, ideally would apply the Heading 3 style to the text before the period and the Body Text style to the remainder of the paragraph. I'm not sure if that is clear, but I can make a video if it is not.

Code:
Sub ChangeAPA2toAPA3()
'
' ChangeAPA2toAPA3 Macro
' Changes from freestanding APA 2 level subhead to run-in APA level 3 subhead. Uses BodyText style to define the paragraph style.
'
    Selection.ClearFormatting
    Selection.Style = ActiveDocument.Styles("Body Text")
    Selection.Range.Case = wdLowerCase
    Selection.Range.Case = wdTitleSentence
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeBackspace
    Selection.TypeText Text:=". "
    Selection.MoveLeft Unit:=wdCharacter, Count:=2
    Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
    Selection.Style = ActiveDocument.Styles("Heading 3")
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.Font.Bold = wdToggle
End Sub
Reply With Quote
Reply

Tags
heading styles, macro, recorder



Similar Threads
Thread Thread Starter Forum Replies Last Post
Applying heading style to multiple pages at once jane.bugai Word 5 02-24-2017 04:05 PM
applying heading style within paragraph using macro Using heading style level in a paragraph kam Word 7 03-24-2014 02:58 PM
applying heading style within paragraph using macro Macro to replace one specific heading style with another ubns Word VBA 44 09-04-2012 08:17 PM
applying heading style within paragraph using macro Applying style to first part of paragraph foxtrot Word 3 07-24-2012 07:30 AM
Character style stripped while applying paragraph style sams_gates Word 0 08-29-2009 02:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:34 AM.


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