![]() |
#16
|
|||
|
|||
![]()
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 |
#17
|
||||
|
||||
![]() Quote:
Code:
Application.OrganizerCopy Source:=.AttachedTemplate.FullName, Destination:=.FullName, _ Name:="StyleName", Object:=wdOrganizerObjectStyles Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#18
|
|||
|
|||
![]()
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 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 |
#19
|
||||
|
||||
![]()
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 |
#20
|
|||
|
|||
![]()
Thanks. Hope this will make it clear.
|
#21
|
||||
|
||||
![]()
Why, oh why, are you using:
Name:=.Styles("Custom Breakout")
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#22
|
|||
|
|||
![]()
All Done.
![]() |
#23
|
|||
|
|||
![]()
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 |
#24
|
||||
|
||||
![]()
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] |
#25
|
|||
|
|||
![]()
Thanks Paul.
I think it has stopped working due the debug error. See the attached. |
#26
|
||||
|
||||
![]()
Works fine for me.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#27
|
|||
|
|||
![]()
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? |
#28
|
||||
|
||||
![]()
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] |
#29
|
|||
|
|||
![]()
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? |
#30
|
||||
|
||||
![]()
I can only go on what the error message says:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
ubns | Word | 3 | 08-01-2012 09:42 PM |
![]() |
TheQueenBea | Word | 3 | 06-05-2012 12:12 PM |
![]() |
TheQueenBea | Word | 1 | 05-31-2012 02:22 PM |
![]() |
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 |