Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2012, 04:17 PM
ubns ubns is offline Macro to replace one specific heading style with another Windows 7 32bit Macro to replace one specific heading style with another Office 2010 32bit
Competent Performer
Macro to replace one specific heading style with another
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default Macro to replace one specific heading style with another

Hi,



I want to change a specific heading style in my document to another heading style.

Can someone please provide me a macro for tyhat?
Reply With Quote
  #2  
Old 07-30-2012, 05:11 PM
Charles Kenyon Charles Kenyon is offline Macro to replace one specific heading style with another Windows Vista Macro to replace one specific heading style with another Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
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

How about the Replace function.

Ctrl-H

Click on the More button

Format > Style

Pick the old style for the find window and the new style for the replace window. No text in either.
Reply With Quote
  #3  
Old 08-01-2012, 06:55 PM
ubns ubns is offline Macro to replace one specific heading style with another Windows 7 32bit Macro to replace one specific heading style with another Office 2010 32bit
Competent Performer
Macro to replace one specific heading style with another
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

Thanks, I have been doing like this, but I wanted a sort of macro to do this for me rather than me doing it everytime or incase i forget. so the best case scenario would be at the open of document it could be done.

if that is not possible then atleast -if we can have one macro for this (it will avoid user picking some different style to replace for or with).

Regards

Umesh Banga
Reply With Quote
  #4  
Old 08-01-2012, 07:13 PM
Charles Kenyon Charles Kenyon is offline Macro to replace one specific heading style with another Windows Vista Macro to replace one specific heading style with another Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
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

Quote:
Originally Posted by ubns View Post
Thanks, I have been doing like this, but I wanted a sort of macro to do this for me rather than me doing it everytime or incase i forget. so the best case scenario would be at the open of document it could be done.

if that is not possible then atleast -if we can have one macro for this (it will avoid user picking some different style to replace for or with).

Regards

Umesh Banga
So, record a macro. Name it "AutoOpen" and save it in your document. Make sure the document type is set as a docm.
Reply With Quote
  #5  
Old 08-09-2012, 04:45 PM
ubns ubns is offline Macro to replace one specific heading style with another Windows 7 32bit Macro to replace one specific heading style with another Office 2010 32bit
Competent Performer
Macro to replace one specific heading style with another
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

Hi,

I have created a macro for that however, it throws the following error: "File not found".

I guess because the coding line states:

Application.OrganizerCopy Source:= _
"C:\Users\umeshbanga\AppData\Roaming\Microsoft\Tem plates\Normal.dotm", _
Destination:= _
"C:\Users\umeshbanga\Desktop\Cusworth\reportou t-395271-adhoc-test.doc", _
Name:="Custom Breakout", Object:=wdOrganizerObjectStyles

The green line picking up the filepath and filename in which I recorded the macro. Is there any way I can ask word or write the code to implement the replacement of styles in my current word document which is open (that can be different everytime).

Also every time I have go to developer tab -- and then client on document template and then copy and paste the "custom heading styles" from normal.dotm to current open word document. is there a way that every time word opens it automitcally performs this function?

Thanks in advance.
Reply With Quote
  #6  
Old 08-12-2012, 05:24 PM
Charles Kenyon Charles Kenyon is offline Macro to replace one specific heading style with another Windows Vista Macro to replace one specific heading style with another Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
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

Quote:
Also every time I have go to developer tab -- and then client on document template and then copy and paste the "custom heading styles" from normal.dotm to current open word document. is there a way that every time word opens it automitcally performs this function?
First idea: Create the document from your template with your custom styles (which should probably not be normal.dotm template).

Second idea: Isn't that what you asked Paul to develop a macro to do?
Reply With Quote
  #7  
Old 08-12-2012, 05:45 PM
macropod's Avatar
macropod macropod is offline Macro to replace one specific heading style with another Windows 7 64bit Macro to replace one specific heading style with another Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Why are you trying to access Normal.dot through code? That makes no sense at all for what you said you want to do:
Quote:
change a specific heading style in my document to another heading style
All you need for that is to use Find/Replace to replace one Style with the other.

Given that we're dealing with heading styles, you would only access Normal.dot to:
• modify an existing Style, so that the change applies to all documents. But, since that would only be done once, you wouldn't use code; or
• to ensure a current Style definition gets carried over to the document being opened. In that case, you might use code like:
Code:
Private Sub Document_Open()
With ActiveDocument
  Application.OrganizerCopy Source:=.AttachedTemplate.FullName, Destination:=.FullName, _
    Name:=.Styles(wdStyleHeading2).NameLocal, Object:=wdOrganizerObjectStyles
End With
End Sub
Which you would put into the Document's 'This Document' module. If you were to put it into the Template's 'This Document' module, it could adversely affect documents that shouldn't be changed.

Depending on what you're trying to achieve, though, all you might need to do is to check the 'automatically update document styles' option.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 08-12-2012, 06:25 PM
ubns ubns is offline Macro to replace one specific heading style with another Windows 7 32bit Macro to replace one specific heading style with another Office 2010 32bit
Competent Performer
Macro to replace one specific heading style with another
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

Hi Paul,

I have normally produce a document from some application based on .aspnet or .dotnet (not sure though). it produces the word document - and is saved on local computer. so it is not based on normal.dotm on my computer and does not carry the custom heading style i have created in my normal.dotm document.

I have to manually go to document template and then use the organiser to copy my custom heading stlyes to the particular document (which have been obtained by using the above process) and then use find and replace function.

This document (downloaded one) has lot of heading styles -and I wanted to autmate this process by macro.

so:

1) When document opens (it should autmoatically process the macro to copy the custm heading styles from macro).

2) Then run find and replace function to replace the heading styles.

I understand that I can do this manually, however there are other users who are not that familiar with all these functions, so i was thinking if I can get the macro for that to make it easy for them.

I am sorry if my requirements and the specifications were not clear the first time.

Does the above mentioned code (given by you) will work on that?

Regards

Umesh Banga
Reply With Quote
  #9  
Old 08-12-2012, 06:37 PM
macropod's Avatar
macropod macropod is offline Macro to replace one specific heading style with another Windows 7 64bit Macro to replace one specific heading style with another Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Umesh,

Since your document comes from another application, you cannot have it automatically do anything when you open it, since it won't contain any macro code.

You could have have a Document_Open macro like the one I posted in your Normal template but, as I said, that risks modifying every document you open - unless the document you're interested has something in its name or contents that you can test before doing the processing; in that case, you could add the test code to the macro. Of course, for this to be of any benefit to others, their Normal templates would require the same modification (and they'd also need access to your custom heading Style).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 08-12-2012, 06:51 PM
ubns ubns is offline Macro to replace one specific heading style with another Windows 7 32bit Macro to replace one specific heading style with another Office 2010 32bit
Competent Performer
Macro to replace one specific heading style with another
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

Paul, we have unique text "Statement of Advice" in each of these documents.

Would it help?

Regards

Umesh Banga
Reply With Quote
  #11  
Old 08-12-2012, 07:17 PM
macropod's Avatar
macropod macropod is offline Macro to replace one specific heading style with another Windows 7 64bit Macro to replace one specific heading style with another Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It may help. Where does that text appear.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 08-12-2012, 09:15 PM
ubns ubns is offline Macro to replace one specific heading style with another Windows 7 32bit Macro to replace one specific heading style with another Office 2010 32bit
Competent Performer
Macro to replace one specific heading style with another
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

in the footer of the first page (only).
Reply With Quote
  #13  
Old 08-12-2012, 09:37 PM
macropod's Avatar
macropod macropod is offline Macro to replace one specific heading style with another Windows 7 64bit Macro to replace one specific heading style with another Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could try something like:
Code:
Sub Document_Open()
With ActiveDocument
  If InStr(.Sections.First.Footers(wdHeaderFooterFirstPage).Range.Text, "Statement of Advice") > 0 Then
    Application.OrganizerCopy Source:=.AttachedTemplate.FullName, Destination:=.FullName, _
      Name:="Custom Breakout", Object:=wdOrganizerObjectStyles
  End If
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 08-13-2012, 10:50 PM
ubns ubns is offline Macro to replace one specific heading style with another Windows 7 32bit Macro to replace one specific heading style with another Office 2010 32bit
Competent Performer
Macro to replace one specific heading style with another
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

Hi Paul,

I have done the following -- based on your sugg

Code:
Sub Document_Open()
With ActiveDocument
  If InStr(.Sections.First.Footers(wdHeaderFooterFirstPage).Range.Text, "Statement of Advice") > 0 Then
    Application.OrganizerCopy Source:=.AttachedTemplate.FullName, Destination:=.FullName, _
      Name:="custom breakout".NameLocal, Object:=wdOrganizerObjectStyles
  End If
End With
End Sub
it is giving syntax error.

also if there is more than one style of heading - then how would we enter the multiple style names.

Does this needs to be in "This Document" of Normal.dotm.

Regards

Umesh Banga

Last edited by macropod; 08-14-2012 at 04:19 AM. Reason: Added code tags & formatting
Reply With Quote
  #15  
Old 08-13-2012, 11:03 PM
macropod's Avatar
macropod macropod is offline Macro to replace one specific heading style with another Windows 7 64bit Macro to replace one specific heading style with another Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

But that's not what I suggested! Why have you kept '.NameLocal'?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to replace one specific heading style with another Create and save custom heading style ubns Word 3 08-01-2012 09:42 PM
Macro to replace one specific heading style with another Modify a numbered heading style TheQueenBea Word 3 06-05-2012 12:12 PM
Macro to replace one specific heading style with another Changing numbering in a Heading style TheQueenBea Word 1 05-31-2012 02:22 PM
Macro to replace one specific heading style with another Very frequent heading style, but still not built in Word!!!!! why??? Jamal NUMAN Word 17 06-30-2011 05:47 PM
How to have this Heading – Table of contents style? Jamal NUMAN Word 0 01-13-2011 06:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:50 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