Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 08-14-2012, 03:57 AM
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

Oh I forgot to remove it. I will remove and try.

How do I enter multiple styles in one macro or do i need to save separate macro for each style.

Should I insert it as one of the module Or in "this document" in normal.dotm.

Thanks in advance.

Regards

Umesh Banga
Reply With Quote
  #17  
Old 08-14-2012, 04:25 AM
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

Quote:
How do I enter multiple styles in one macro or do i need to save separate macro for each style.
In that case you'd simply use more lines like:
Code:
Application.OrganizerCopy Source:=.AttachedTemplate.FullName, Destination:=.FullName, _
      Name:="StyleName", Object:=wdOrganizerObjectStyles
with whatever Style names you need to transfer.
Quote:
Should I insert it as one of the module Or in "this document" in normal.dotm.
Document_Open subs are intended to be used in a 'ThisDocument' module.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #18  
Old 08-14-2012, 08:49 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,

Thanks for your reply. I have now tried the following code:

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:=.Styles("Custom Breakout"), Object:=wdOrganizerObjectStyles
  End If
End With
End Sub
It gives the error message "Requested member of the collection does not exist"

I have included this in "This Document" section of the Normal.dotm.

Can you please advice what I am doing incorrectly?

Regards

Umesh Banga

Last edited by macropod; 08-14-2012 at 10:46 PM. Reason: Added code tags & formatting
Reply With Quote
  #19  
Old 08-14-2012, 10:52 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

Which code line gets highlighted? Does whatever template the newly-opened document is attached to contain the 'Custom Breakout' Style? What do you see if you use:
MsgBox ActiveDocument.AttachedTemplate.FullName

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 08-14-2012 at 10:55 PM. Reason: Extra question added
Reply With Quote
  #20  
Old 08-15-2012, 07:05 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 I have attached the screenshot

Thanks. Hope this will make it clear.
Attached Files
File Type: docx Doc1.docx (57.6 KB, 10 views)
Reply With Quote
  #21  
Old 08-15-2012, 07:40 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, oh why, are you using:
Name:=.Styles("Custom Breakout")
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #22  
Old 08-15-2012, 08:12 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

All Done.
Reply With Quote
  #23  
Old 08-19-2012, 10:37 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,

For some reason this code has stopped working now? any idea why? There is no message but it does not import the custom heading styles from the normal.dotm in the currently opened document. this code was worknig feww days ago.

I do not know what has happened now.

I have attched the code for your reference


Code:
Sub Document_Open()
With ActiveDocument.Content.find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = "monitor"
  .Replacement.Text = "review"
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = False
  .MatchWholeWord = True
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = "folder or on a seperate disc"
  .Replacement.Text = "folder"
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = False
  .MatchWholeWord = True
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Execute Replace:=wdReplaceAll
End With
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
   Application.OrganizerCopy Source:=.AttachedTemplate.FullName, Destination:=.FullName, _
   Name:="Custom Breakout Subheading", Object:=wdOrganizerObjectStyles
   Application.OrganizerCopy Source:=.AttachedTemplate.FullName, Destination:=.FullName, _
   Name:="Custom Page Heading", Object:=wdOrganizerObjectStyles
   Application.OrganizerCopy Source:=.AttachedTemplate.FullName, Destination:=.FullName, _
   Name:="Custom Page Subheading 1.0", Object:=wdOrganizerObjectStyles
   Application.OrganizerCopy Source:=.AttachedTemplate.FullName, Destination:=.FullName, _
   Name:="Custom Paragraph Main Heading 1.0", Object:=wdOrganizerObjectStyles
   Application.OrganizerCopy Source:=.AttachedTemplate.FullName, Destination:=.FullName, _
   Name:="Umesh Table Style", Object:=wdOrganizerObjectStyles
 End If
End With
End Sub
Reply With Quote
  #24  
Old 08-19-2012, 11:01 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

I have no idea whay your code might have stopped working. Have you tried re-starting Word?

FWIW, the code you posted could be reduced to:
Code:
Sub Document_Open()
Dim StrSty As String, i As Long
StrSty = "Custom Breakout,Custom Breakout Subheading,Custom Page Heading," & _
  "Custom Page Subheading 1.0,Umesh Table Style"
With ActiveDocument
  With .Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Text = "monitor"
    .Replacement.Text = "review"
    .Execute Replace:=wdReplaceAll
    .Text = "folder or on a seperate disc"
    .Replacement.Text = "folder"
    .Execute Replace:=wdReplaceAll
  End With
  If InStr(.Sections.First.Footers(wdHeaderFooterFirstPage).Range.Text, "Statement of Advice") > 0 Then
    For i = 0 To UBound(Split(StrSty, ","))
      Application.OrganizerCopy Source:=.AttachedTemplate.FullName, Destination:=.FullName, _
        Name:=Split(StrSty, ",")(i), Object:=wdOrganizerObjectStyles
    Next
  End If
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #25  
Old 08-19-2012, 11:23 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 Paul.

I think it has stopped working due the debug error.

See the attached.
Attached Images
File Type: png Macro-Debug.PNG (37.2 KB, 17 views)
Reply With Quote
  #26  
Old 08-19-2012, 11:36 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

Works fine for me.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #27  
Old 08-20-2012, 12:11 AM
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

There is definitly an issue. It normally comes - when the document comes with the information bar "Enable Content". I will take the screenshot of that when it happens agian.

On the similar note - I have a document in which I have locked the date fields. When I reopen the document to do some editing, the attached error comes.

Any suggestions how to over come this debugging issue?
Attached Images
File Type: png Macro-Debug.PNG (29.4 KB, 16 views)
File Type: png Macro-Debug-1.PNG (40.9 KB, 16 views)
Reply With Quote
  #28  
Old 08-20-2012, 01:35 AM
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

That error has nothing to do with fields. It occurs because you have protected part of the document (eg with form protection).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #29  
Old 08-20-2012, 03:13 AM
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 do not think I have any protected form or part in the document.

Can you please advice how I can find this if there is any. I mean is there a way to find - which part of section is actually protected?
Reply With Quote
  #30  
Old 08-20-2012, 05:28 AM
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

I can only go on what the error message says:
Quote:
Runtime Error 4605:

This method or property is not available because the object refers to a protected area of the document.
The fact your code shows 'Activedocument.find' instead of 'Activedocument.Find' concerns me, as 'Find' should have a capital 'F'. That may indicate some template corruption and/or a fault with your Word installation. As a first step, I'd suggest repairing Word (via Programs & Features > Microsoft Office > Change in the Windows Control Panel). If that doesn't resolve things, you may need to delete & rebuild the template.
__________________
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 08:31 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