Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent: Make styles in tv-script visible by userform

Status
Not open for further replies.

Madeleinenorway

Technical User
Jun 23, 2011
10
NO
[ponytails2]Hi there,

Is there an easy way in vba (word 2010) to detect the used styles in a document and add them as check boxes on a userform, where I can hide/show the styles by toggle check box status? And automatically add another check box, named "All visible" that shows/hide all? (Except from two pre-defined styles). And - if all the styles are present - the "All visible" check box turns on? And vice versa?
The reason I ask, is that I am a writer/producer - and when going into production I write notes that aren´t interesting for the whole crew.

I kind of achieved this through an endless, stupid and not bug-free code. (Sometimes I have to check the boxes all over again, even if I have pressed the "All visible"-checkbox)

I think there might be a "each/next"-statement that could do the trick - but I am a newbee. Are there someone out there who could help me write a more efficient code that:
1 ) scans the used styles in the document
2 ) pass them to a userform (whith names )
3) when checkbox is pressed - the dependent style is toggles its visible/not visible status?

The styles I uses now are:
TOC
Heading
Sequence
Synopsis
Sceneheading (numbered) (Should always be visible)
Action
Technichians
Scenography
Administration
Character/Dialogue (which is actually two different styles - but they have to show up at the same time)

Maybe with the ability to change styles easy - and fire the same code?
Thank you so much in advance.

Best,
Madeleine :)


Embedded: Testdocument. If you call the macro "Synlige" (Visible) my UserForm will show up.

A little snippet of code from my UserForm ("Visalle" means "Show all")

Code:
Private Sub Admin_Change()
If Admin.Value = False Then
ActiveDocument.Styles("Admin").Font.Hidden = True
ElseIf Admin.Value = True Then
ActiveDocument.Styles("Admin").Font.Hidden = False
End If
selvtest
End Sub

 

Private Sub selvtest()
Dim ctl As Control
Dim j As Long
Dim msg As String
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.CheckBox Then
If Me.Controls(ctl.Name).Value = True Then
j = j + 1
End If
End If
Next
If j <> 6 Then
Me.Visalle.Value = False
Else

If Me.Visalle.Value = True Then
Me.Visalle.Value = False

Else
Me.Visalle.Value = True
End If
End If
End Sub
 
hi,

Please post VBA questions in forum707.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Something like:

Code:
Public Sub Stylin()
Dim myStyles As Style
For Each myStyles In ActiveDocument.Styles
    If myStyles.InUse = True Then MsgBox (myStyles.NameLocal)
Next

End Sub
 
Thank you so much for replying mintjulep, as I am on a deadline here :). Tried your code - but it just listed all styles in document - not the USED styles? I got like a hundred results?

Best,
M
 



Seems to work.

Open NEW empth doc. Result list...
[tt]
Default Paragraph Font
No List
Normal
Table Normal
[/tt]
ADDED Heading1 style to a paragraph in the new doc. Result list...
[tt]
Default Paragraph Font
Heading 1

No List
Normal
Table Normal
[/tt]




Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


Yes, the OP clearly stated, "...to detect the used styles in a document..."

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi again, SkipWought. I tried your method in a new document - and got the same result. The problem is - I just need my custom styles. Like
Customtitle
Sequence
Sceneheading
Synopsis
Action
Character
Dialogue
And 3-4 custom headings for writing notes to the staff:
Scenographer
Props
Camera
Etc.

Is it possible what I am trying to achieve?

Best,
Madeleine

(I got a warning that this should be posted somewhere else? Do you know how to move the post?)

 


I added a custom style ...
[tt]
Default Paragraph Font
No List
Normal
SkipVought

Table Normal
[/tt]
Don't understand your dilema.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip,
I am trying to auto-build a userform based on the custom-made styles in the document. Which means; no table-style, no normal-style and so on. Just the styles I have made - turned into check boxes which I can check and uncheck to make a report. I have managed to do this a rather crocky way - with an endless code which does not seem to be bug free. What I am trying to achieve, is a UserForm (autobuild from custom-made styles) with checkboxes to hit to show just parts of the document. Thank you for giving me hints in direction of pulling styles from the document. But how do I get to the point that I can auto-pull the custom style to a UserForm for hiding/unhiding text. And on this UserForm I cant have CheckBoxes with "Default paragraph font", "No list" and so on. Just the styles i mentioned before. Thank you for your patient.
 



You must have a list of 'stock' style that you can remove from the myStyles.InUse list to load your control.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 



BTW, have you looked in VB Help for Style to see the list of properties & methods for the Style Object?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
It's consternating that the results of .InUse are different from the styles listed in the styles and formatting pane with "Formatting in use" selected.

Help for .InUse reveals
Help said:
InUse Property
True if the specified style is a built-in style that has been modified or applied in the document or a new style that has been created in the document. Read-only Boolean.

Remarks
This property doesn't necessarily indicate whether the style is currently applied to any text in the document. For instance, if text that's been formatted with a style is deleted, the InUse property of the style remains True. For built-in styles that have never been used in the document, this property returns False.

I'm sure it would be possible to write a procedure to figure out what styles are actually applied to text in a document. I'm also sure that it won't be easy.

Since your list of styles is short, and you're pressed for time you might want to consider just hard-coding them, or putting them in a text file and reading the names from there.

 
This might trim the list down a bit:

Code:
Public Sub Stylin()
Dim myStyles As Style
For Each myStyles In ActiveDocument.Styles
    If myStyles.InUse = True [b][green]And myStyles.BuiltIn = False[/green] [/b]Then MsgBox (myStyles.NameLocal)
Next

End Sub
 



Here's an example of listing all the styles used in doc paragraphs...
Code:
Sub FindStypes()
    Dim pg As Paragraph
    
    For Each pg In ThisDocument.Paragraphs
        Debug.Print pg.Style.NameLocal
    Next
End Sub

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Eh... I am not sure about the difference between a style and a paragraph? I think the best is to just have one variant to stick to - the style object? Or what do you mean. Sorry for being such a newbee. M
 


this is just proof of concept...
Code:
Sub FindStypes()
    Dim pg As Paragraph, i As Long
    
    For Each pg In ThisDocument.Paragraphs
        For i = 1 To pg.Range.Characters.Count
            Debug.Print pg.Range.Characters(i).Style.NameLocal
            
        Next
    Next
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip,
Here in Norway it is almost midnight - and I am going on a shoot tomorrow, so I have to go to bed. But thank you SOOOOO much for your help. I did not realize befor now, that it is possible to get this kind of help from a forum - you have been so helpful. My deadline is on monday. You have helped me a lot all ready. But maybe I will have some questions tomorrow. Will it be okay to post you then? Just say "No" if you think you spent to much time on this. Thank you anyway. :):)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top