I am new to development and have created a macro which first creates styles 1-9, then assigns them to a list template. Everything works fine to this point; however, in the current scenario, a user may include many different list templates. If the user uses more than one list template, I want them to be able to select a previous list template again… if they select the previous list template, the macro fails since the styles have already been created. I think I’m looking for an IF statement to begin looking for the styles THEN if not found, create… ELSEIF found THEN only apply list template. For the life of me I cannot figure out the required code to look for the style in the Active Document… can anyone help? Thanx in advance… trish
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
If Active Document Contains Style (Word 2002)
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » If Active Document Contains Style (Word 2002)
- This topic has 6 replies, 3 voices, and was last updated 22 years ago.
AuthorTopicWStkrokosh
AskWoody LoungerApril 28, 2003 at 8:44 pm #386685Viewing 0 reply threadsAuthorReplies-
kdock
AskWoody PlusApril 29, 2003 at 5:00 pm #672103I wish I knew a little more about the circumstances of this macro; I might have just a little more advice
However, on the face of it, it seems as if you need an error handler.
This code checks for the style using Set (see below). Setting a value to an object that doesn’t exist produces an error which you can capture and use to your benefit.
Sub DoesNewStyleExist(fdummy As Boolean) ' Check for style named "StyX" ' If not there, goes to error handler Dim StyleExist As Object Dim S As Integer Dim Style2 On Error GoTo StyleNotThere Set StyleExist = ActiveDocument.Styles("Sty1") If StyleExist.NameLocal = ("Sty1") Then End If Exit Sub StyleNotThere: ' Your code to create the styles and link to list template End Sub
BTW (and forgive me if you already knew) “(fdummy As Boolean)” keeps a macro from appearing in Word’s list of macros.
Does this help?
Kim
-
WStkrokosh
AskWoody Lounger -
WStkrokosh
AskWoody LoungerMay 22, 2003 at 2:40 pm #678909Hi Kim… Sorry for bugging you about this, I posted this and have not received the answer that I want and, since you were so ingenious with this first puzzle, I thought you may be able to help with my next issue… If you are unable to help, I completely understand… thanx in advance for any ideas/suggestions…
I have created a macro to create a list template with the help of many of you! I have run into one problem which I’ve tried to ‘logically’ figure out but with no success. Initially, the macro for each ‘scheme’ (list number template) which I create clears the list gallery, then begins looking for the first style in that particular list, if it exists then it simply reattaches the list template; however, if it does not exist it goes to the error handler area to begin creating all the styles then attaches the list template. The code is as follows:
For Each listgal In ListGalleries
For i = 1 To 7
listgal.Reset (i)
Next i
Next listgal‘ Check for style named “ArticleN2 L1”
‘ If not there, goes to error handlerDim StyleExist As Object
Dim S As Integer
Dim Style2
On Error GoTo StyleNotThereSet StyleExist = ActiveDocument.Styles(“ArticleN1 L1”)
If StyleExist.NameLocal = (“ArticleN1 L1”) Then‘ Check for List Template in document – if there, uses current,
‘ if not, createsDim OLstTemp As ListTemplate, TemplateFound As Boolean
For Each OLstTemp In ActiveDocument.ListTemplates
If OLstTemp.Name = “ArticleN1” Then
TemplateFound = True
Exit For
End If
Next OLstTempIf TemplateFound Then
Set OLstTemp = ActiveDocument.ListTemplates(“ArticleN1″)
Else
Set OLstTemp = ActiveDocument.ListTemplates.Add(OutlineNumbered:=True, _
Name:=”ArticleN1”)
End IfThe current problem which I’m trying to figure out is that all the styles are based on a style which I created called BodyText (not Word’s built-in Body Text). This macro works fine for all new documents; however, if an older document is opened and the user wants the numbering applied it dies with error 5834 – not finding the based style BodyText. What I need is for it to look for the BodyText style first and if it does not exist then create, then look for the next style, e.g., ArticleNo1 L1 and continue the remainder of the macro. I tried to use another error handler after the first error handler… failed… tried to call another procedure upon error… failed… tried more if statements after error handler… failed??????????????
I thought about changing the ArticleNo. L1 error handler to BodyText; however, a user may select more than one ‘scheme’ (list template) in their document. Logically, I’m fried like an egg… any ideas? Thanx for your help in advance…
-
WSHansV
AskWoody LoungerMay 22, 2003 at 3:38 pm #678928You could insert code after resetting the listgalleries:
‘ Check for style named “BodyText”
‘ If not there, create itDim StyleBodyText As Style
On Error Resume Next
Set StyleBodyText = ActiveDocument.Styles(“BodyText”)
If Err 0 Then
Err.Clear
Set StyleBodyText = ActiveDocument.Styles.Add(“BodyText”)
With StyleBodyText
‘ Set style properties here, for example:
.Font.Name = “Arial”
End With
End If -
WStkrokosh
AskWoody Lounger
-
-
kdock
AskWoody PlusMay 22, 2003 at 8:53 pm #679011(Edited by HansV to activate link to post – see Help 19)
Hi Trish, I’m going to post my response to the active thread (post 256454). Hopefully, it will be helpful… Kim
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Windows Update orchestration platform to update all software
by
Alex5723
4 hours, 17 minutes ago -
May preview updates
by
Susan Bradley
16 minutes ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
6 hours, 2 minutes ago -
Just got this pop-up page while browsing
by
Alex5723
3 hours, 58 minutes ago -
KB5058379 / KB 5061768 Failures
by
crown
54 minutes ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
4 minutes ago -
At last – installation of 24H2
by
Botswana12
19 hours, 49 minutes ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
40 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
1 day, 8 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
1 day, 1 hour ago -
Limited account permission error related to Windows Update
by
gtd12345
1 day, 21 hours ago -
Another test post
by
gtd12345
1 day, 21 hours ago -
Connect to someone else computer
by
wadeer
1 day, 16 hours ago -
Limit on User names?
by
CWBillow
1 day, 19 hours ago -
Choose the right apps for traveling
by
Peter Deegan
1 day, 9 hours ago -
BitLocker rears its head
by
Susan Bradley
17 hours, 1 minute ago -
Who are you? (2025 edition)
by
Will Fastie
15 hours, 58 minutes ago -
AskWoody at the computer museum, round two
by
Will Fastie
1 day, 11 hours ago -
A smarter, simpler Firefox address bar
by
Alex5723
2 days, 7 hours ago -
Woody
by
Scott
2 days, 17 hours ago -
24H2 has suppressed my favoured spider
by
Davidhs
16 hours, 38 minutes ago -
GeForce RTX 5060 in certain motherboards could experience blank screens
by
Alex5723
3 days, 7 hours ago -
MS Office 365 Home on MAC
by
MickIver
3 days, 1 hour ago -
Google’s Veo3 video generator. Before you ask: yes, everything is AI here
by
Alex5723
3 days, 21 hours ago -
Flash Drive Eject Error for Still In Use
by
J9438
16 hours, 23 minutes ago -
Windows 11 Insider Preview build 27863 released to Canary
by
joep517
4 days, 16 hours ago -
Windows 11 Insider Preview build 26120.4161 (24H2) released to BETA
by
joep517
4 days, 16 hours ago -
AI model turns to blackmail when engineers try to take it offline
by
Cybertooth
3 days, 20 hours ago -
Migrate off MS365 to Apple Products
by
dmt_3904
3 days, 20 hours ago -
Login screen icon
by
CWBillow
3 days, 11 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.