Make styles in tv-script visible by userform

  • 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 [:)]
    A little snippet of code from my UserForm ("Visalle" means "Show all")

  • Re: Urgent: Make styles in tv-script visible by userform


    Did I miss something, or did you edit your post?? :) - it seemed a lot simpler when I first looked so went off to test some code...


    I don't know about 2010, but the following lists the styles in use in 2007. You seem to know a bit about VBA so perhaps it'll be useful. Am now going to read your post fully..


  • Re: Urgent: Make styles in tv-script visible by userform


    Thank you so much. I think i by mistake edited my post. There was something about wrapping the code in brackets or something? I will have a look and see what my post looks like.
    Best,
    Mad

  • Re: Urgent: Make styles in tv-script visible by userform


    Hi again :)
    I tried your code - but I got all the word built-in-styles showing in the immediate-window? Do I have to delete all the styles first? A bit afraid of deleting built-in-styles?

    Best,
    M

  • Re: Urgent: Make styles in tv-script visible by userform


    It just lists the styles in use... as I said I must have misread/misunderstood what you're trying to do...


    My understanding now is you want to list specific styles on a userform and then make text formatted as style X visible/invisible depending on the value of the associated checkbox. That correct?

  • Re: Urgent: Make styles in tv-script visible by userform


    Yes, I think that is correct. I have a document - formatted with like 7-10 different styles. From Sequence, Sceneheading, Synopsis, Action, Character, Dialogue, Photographer, Scenographer and so on. I would like to have a UserForm which is based on this styles which I have createded (some of them due to factory standards) - and then - by enable or disable checkboxes - I can hide/unhide the custom styles. And by doing this, building specific reports to the crew-members that need just that kind of information (in other words - hiding information that is not interesting for other crew-members). Thank you for taking your time. :)

  • Re: Urgent: Make styles in tv-script visible by userform


    Try the attached. Obviously it's very rough. When you open the document a user form will be displayed. This lists some of your styles but obviously they don't exist in this document, so I also added a checkbox for the style Title which does exist.


    When the form is loaded, all the checkboxes are disabled and their value set to false (unchecked).


    It then uses that bit of code I posted earlier to enumerate all the defined styles. If a style is used, any checkbox for that style is enabled and it's value set True. Tlhe style can then be displayed or hidden by clicking the checkbox...


    The code is *rough* - it's just an example.


    Note: The document contains macros - you will need to enable them when you load it.


    *EDIT* Problems uploading - uploading a DOCM file seems to be an issue. Rename the attachment to .DOCM before opening in Word

  • Re: Urgent: Make styles in tv-script visible by userform


    And one minor change - make the checkbox True or False depending if the font is currently hidden or not


    Code
    If y.InUse Then
             Me.Controls(strName).Value = (y.Font.Hidden = False)
          End If
  • Re: Urgent: Make styles in tv-script visible by userform


    Hi again, there. I tried to save the attachment as a .dotm. But no userform shows up when I open it? Do I have to activate anything? Best, Madde.

  • Re: Urgent: Make styles in tv-script visible by userform


    I don't have Word 2010 but would assume it still has the 'Enable Macros' dialog when you open it. Sometimes in 2007 it's just a silly "Security warning - Macros have been disabled" warning with an 'Options' button above the document though...

  • Re: Urgent: Make styles in tv-script visible by userform


    I tried to open it, but the form did not load. I ran the form from vba - but everything is disabled (as you mentioned). I think this really is what I am trying to achieve. But why does the UserForm not load on open? And how do I enable the check-boxes? Sorry for the hazzle. Thank you, anyway.

  • Re: Urgent: Make styles in tv-script visible by userform


    I think I am getting there :) Awsome. I am Norwegian - so the name "Title" is "Tittel" in Norwegian. In your code you disable styles that are not in the document? I tried adding "Title" as a style - and all of the sudden - the "Title"-checkbox was enabled. I checked it - and the style disappeared. Do you know how to show all/hide all? And reflect the changes in the userform? If you got time. Thank you, anyway. :):)

  • Re: Urgent: Make styles in tv-script visible by userform


    Try something... Load a copy of your document as well as the one I sent. Go to the VBA editor (Press Alt-F11 on any of the documents), click and drag UserForm1 from my document to yours and then run it in your document.


    You can run it by Pressing Ctrl-G in the VBA editor to display the Immediate Window, Type (ignoring the quotes "userform1.show vbmodeless" and press enter, the userform should load. Then see if any of the checkboxes for your styles are enabled.

  • Re: Urgent: Make styles in tv-script visible by userform


    Crossed posts there, sorry. I don't have time tonight, but if you attach a copy of your document with the styles and ALL of your hard work removed, but some random text instead, I'd be happy to do that for you tomorrow. (I appreciate your post title says 'Urgent' but I have to go in a little while.

  • Re: Urgent: Make styles in tv-script visible by userform


    Off couse. I have to do it my self. Thank you so much for your help. If you have the time and will - you can help me tomorrow. But you allready done a lot. But maybe I will have some questions tomorrow. I will try to post you, but if you dont have the time, thank you anyway :) :) :). You tracked me in the right direction here :)

  • Re: Urgent: Make styles in tv-script visible by userform


    Like I said, I'd be happy to get it working for you. If you do decide to upload a copy please remember to save it in 2007 format so I can open it. Other than that, I'll pop in tomorrow some time.


    'Night

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!