Results 1 to 12 of 12
  1. #1
    New Lounger
    Join Date
    Nov 2001
    Location
    Sydney, Australia, New South Wales, Australia
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro Problems (97-SR 2)

    Attention VB Gurus

    I have to create a distribute a series of project plan 'templates' as .doc files, which are downloaded from the intranet (IE) by the user community. I need to give them the ability to remove all hidden text guidelines (which are based on a style called 'Hidden'), so I've added a macro to remove all hidden text style from the document, and attached this macro to a toolbar button. It works fine on my PC, but not for anyone else. The macro starts ok, because the Message box displays asking the user to confirm the removal of all hidden text, but nothing else happens.

    I'm puzzled, because the toolbar and macros seem to be attached to the file, otherwise the message box wouldn't appear. I've copied the macro below, and am hoping someone can sort me out. Note that I have this macro in three formats on my PC, it's listed under 'Normal', it's listed under the actual file, e.g. Project (ASM120 PMP v3.0), and it's also listed under the file's template, e.g. TemplateProject (SECO v1).

    I don't know why it's a 'Sub', and there is another 'Sub' above it called 'Remove End Notes'. I just want a simple macro to remove all hidden text style, and I don't know the distinction between Module1 and NewMacros listed under Modules in the VB Editor window. I've attached the file (after zipping it) in case any wizard out there wants to clean it up for me. I had to cut the file down to size, so ignore the content, but please look at how the various macros are attached.
    --------------------------------------------------------
    Sub RemoveHiddenText()
    '
    ' RemoveHiddenText Macro
    ' Macro recorded 05/07/02 by MCahill
    '
    If MsgBox("Remove all hidden text from this document?", _
    vbQuestion + vbYesNo) = vbNo Then Exit Sub

    Selection.Find.Style = ActiveDocument.Styles("Hidden")
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    --------------------------------------------------------

    Thanks in advance (I don't know what I'd do without this fabulous forum)
    Mary
    Attached Files Attached Files

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro Problems (97-SR 2)

    Both buttons work fine for me. I did have to delete one extra "End Sub" line in the code; in the Visual Basic Editor, choose Debug|Compile Project and the duplicate line will be highlighted.

    So...why it doesn't work for your users, hmmm... I believe the answer is that they are not viewing hidden text at the time they run the replace. If I turn off the viewing of hidden text, mine doesn't replace either. You might have to add this into your code to work around it, or tell the users to Show Hidden before running replace. The former approach is more likely to be effective.

    Finally, on your questions about procedure names and modules. Generally speaking, all procedures are named Sub Something. Once upon a time this probably stood for subroutine, but nowadays we are more likely to say sub procedure. When you choose Insert|Module Module1 is created. You can rename it anything you like. When you record a macro, it is stored in New Macros. You can move the procedures around if you wish; you don't need both modules.

  3. #3
    New Lounger
    Join Date
    Nov 2001
    Location
    Sydney, Australia, New South Wales, Australia
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Problems (97-SR 2)

    Thank you, I am constantly amazed at how fast I get a response from this forum!

    So, one of the culprits was an extra 'End Sub' - interesting because the macro still worked for me. The fact that the macro only works if the hidden text is displayed surprises me, but since I always work in that mode I would never have picked this up. You say I can add code to the macro to turn on the hidden text display before trying to remove it - would you please post the lines of code for this?

    Thanks for the info on modules - I'll try renaming so I can sort out what goes where.

    Thanks again for your (always helpful) expert advice.
    Mary

  4. #4
    Star Lounger
    Join Date
    Jun 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Problems (97-SR 2)

    at the top of your sub drop this in;

    ActiveWindow .View .ShowHiddenText = True

    and the last command before exiting is to turn this false,
    the unwritten law is you never leave your user with their options messed up.

    A good? way to get going with VBA is to use the macro recorder to record something and then edit the resultant code.
    In this case I recorded setting hidden text option & then edited out everything that wasn't of interest.

  5. #5
    Star Lounger
    Join Date
    Jun 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Problems (97-SR 2)

    as a by thought - as distinct from coherent thought.

    I use a lot of "BlueText' . Thats a macrobutton that deletes ( we use a italic blue) itself and carries out some function.

    for example instead of having your user delete the <Project Name> on your front page and type in the name try this.
    put this macro in your template;

    Sub DeleteBlueText()
    Selection.Delete Unit:=wdCharacter, Count:=1
    End Sub


    then instead of <Project Name> on your front page insert the field;

    {MACROBUTTON blueTextDelete Double Click to enter Project Name } which will appear on the doc as

    Double Click to enter Project Name


    When the user double clicks this macro it deletes itself and allows the project name to be entered in
    one operation. I also use these to launch multiple choice selections etc, its very useful for reducing the
    keystrokes our users need to make.

  6. #6
    New Lounger
    Join Date
    Nov 2001
    Location
    Sydney, Australia, New South Wales, Australia
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Problems (97-SR 2)

    Frank

    I appreciate all the hints and tips. I do use the 'record' function to create macros, but I get confused in the ensuing macro hierarchy (projects, modules, objects, etc). I save everything to my normal.dot, then I also save it to the actual file and to that file's template (when it's not based on normal.dot). Then, when I try to test the macros and toolbar buttons, I never know which one is being used. Hence, everything works fine on my PC, but not when it's distributed to other users.

    Thanks for the additional information re MACROBUTTON fields. Unfortunately we've had our fingers burned using MACROBUTTON fields in some of our previous forms - they blew out the size of the file and made working with the file extremely slow (up to 45 seconds just to open it!). I didn't create the file with all the MACROBUTTONS, but they were used extensively throughout a checklist type form (in each tickbox). Perhaps MACROBUTTONS were the wrong choice for that form, but the damage has been done (we had to re-issue the form without MACROBUTTONS).

    Cheers and many thanks for your assistance
    Mary

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro Problems (97-SR 2)

    Here's one way to store and restore the Show All setting that your first toolbar button toggles. I marked the new stuff in blue and re-arranged the Find part a tiny bit:
    <pre>Sub RemoveHiddenText()
    '
    ' RemoveHiddenText Macro
    ' Macro recorded 05/07/02 by MCahill
    '
    If MsgBox("Remove all hidden text from this document?", _
    vbQuestion + vbYesNo) = vbNo Then Exit Sub

    <font color=blue>' Store default state of ShowAll and toggle to true if not true
    Dim blnShowAll As Boolean
    If ActiveWindow.View.ShowAll = True Then
    blnShowAll = True
    Else
    blnShowAll = False
    ActiveWindow.View.ShowAll = True
    End If</font color=blue>

    ' Find and replace
    With Selection.Find
    <font color=blue>.ClearFormatting</font color=blue>
    .Style = ActiveDocument.Styles("Hidden")
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
    ' Clear the find criterion
    <font color=blue>.ClearFormatting</font color=blue>
    End With

    <font color=blue>' Reset the Show All setting back to what it was
    ActiveWindow.View.ShowAll = blnShowAll</font color=blue>
    End Sub</pre>

    (As you may know, code that is posted in PRE tags cannot be copied directly into a module; copy and paste it into a Word document first, and then re-copy and paste into the VBE.)

    You do not need the various macros relating to Endnotes, as far as I can tell, so you can slim down your code quite a bit.

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Problems (97-SR 2)

    You are falling into the pitfalls of using macro recording.
    See http://www.standards.com/OhMyWord/MacroRecording.htm.

    And see the Word VBA book list at my web site.

  9. #9
    Star Lounger
    Join Date
    Jun 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Problems (97-SR 2)

    Ohhhh memories of my own introduction to Word VBA. Even considered sacrificing a goat to the goddess Araldite for help.

    You can reduce the confusion of having multiple copies of the same macro by identifying its module as well
    so instead of using a macro called MyMacro you could do something like

    MyProject.MyModule.MyMacro

    Its not a good idea to load up your Normal.dot with macros as its quite vulnerable to corruption.
    I have a special template in my startup directory to hold my macros and use Words Work pull down
    to keep it handy.

    Though you haven't said that you distribute your work as documents with the code in them( which will blow out your doc
    sizes (and put them on tranquilizers), its probably a bad idea to distribute docs.
    Its better to distribute the template (contains all the code, and password protected) that way the document is smaller
    and faster.
    Frank

  10. #10
    New Lounger
    Join Date
    Nov 2001
    Location
    Sydney, Australia, New South Wales, Australia
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Problems (97-SR 2)

    First, a huge thank you to all who sent advice, it sure was appreciated. Just when you think you're through the maze, another twisted turn appears. Now that I'm sorting through the macros and templates, I've got a problem deploying the templates via our intranet / portal. Can anyone help with the following (also posted in the IE Forum).

    (Using IE 5.5 &/or IE 6, MS-Word 97)
    We want to deploy true templates (.dot, .xlt) via our intranet portal and have discovered that IE re-interprets a .dot file as a .doc file when doing a 'Save target as' and changes the file extension to .doc (.xlt to .xls).

    If we manually change the file extension in the 'Save target as' dialogue box then the template, plus it's associated AutoOpen macros, works fine. Unfortunately, this is not a viable solution for our users.

    If we deploy the templates in a zip file, then unzip the templates, all is ok. Unfortunately, our users complain about the 'extra step' required to download a zip file and unzip the files.

    We've already eliminated filename size, the problem occurs for both long and short filenames.

    Why should IE try to reinterpret the file extension, effectively not recognising the difference between normal Word/ Excel files and template file types? Because of this issue, and our expanding use of macros and custom toolbars (hence the need to deploy true templates) our Process Mgr has banned me from issuing templates. This means I cannot use macros to automate many routine documentation functions, which ultimately makes the authoring process easier for our users.

    Any help appreciated
    Thank you
    Mary Cahill

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro Problems (97-SR 2)

    I can think of two reasons for this. First would be security settings either in the browser or on the server; Microsoft trying to be helpful. The second would be an error or missing setting in the server configuration. There was a thread recently either on the IE or web coding boards about Photoshop .PSD files wanting to save as .htm files. If you find that thread, there is a solution for an Apache-based server toward the end. I have no idea what server/portal you're running, but it might give your webmaster a useful hint.

  12. #12
    New Lounger
    Join Date
    Nov 2001
    Location
    Sydney, Australia, New South Wales, Australia
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Problems (97-SR 2)

    JScher

    Thank you for the advice. I've already trawled through the IE forum and found the thread re Photoshop .PSD files and sent that information to our techos. I hope the solution is a simple MIME Type setting because I've never run into this problem before (I've been able to deploy templates via the intranet at other companies).

    Once again, Woody's comes through with prompt advice.
    Thanks again
    Mary Cahill

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •