Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

What is wrong in this macro ? (works in 2003, problem with 97)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Doue - 31 Mar 2007 13:38 GMT
Hi,

Can anyone help me find what the problem is with this autoopen macro
that works perfectly in Word 03 but has a problem in 97? When there is
hidden text in the document being opened, I do get the desired warning,
but the whole text appears black, to return to normal after the warning
has been acknowledged. When there are both comments and hidden text, the
problem does not exist.

Thanks a lot, I am stumped!

Sub autoopen()
'
' autoopen Macro
' Macro recorded 09/26/99 by John

If ActiveDocument.comments.Count > 0 Then
    With ActiveDocument
    i = .comments.Count
    End With
    Call MsgBox("There are " & i & " Comments in the document")
End If

Dim oRg As Range
   Set oRg = ActiveDocument.Range
   ActiveWindow.View.ShowHiddenText = True
   With oRg.Find
      .Format = True
      .Forward = True
      .Font.Hidden = True
      If .Execute Then
         oRg.Select
         With ActiveWindow.View
            .ShowHiddenText = True
            .ShowAll = True
         End With
         Call MsgBox ("Hidden text!")
      Else
         ActiveWindow.View.ShowHiddenText = False
      End If
   End With

With Options
        .ReplaceSelection = True
        .AllowDragAndDrop = True
        .AutoWordSelection = False
        .INSKeyForPaste = False
        .SmartCutPaste = True
        .AllowAccentedUppercase = False
        .PictureEditor = "Microsoft Word"
        .TabIndentKey = True
        .Overtype = False
End With
If ActiveDocument.Bookmarks.Exists("Lastedit") = True Then
    ActiveDocument.Bookmarks("Lastedit").Select
    Selection.GoTo What:=wdGoToBookmark, Name:="Lastedit"
    N = sndPlaySound("E:\WAVEFILES\Attn.wav", 0)
    ActiveDocument.Bookmarks("Lastedit").Delete
End If
CommandBars("Reviewing").Visible = False

With ActiveWindow
        .DisplayHorizontalScrollBar = True
        .DisplayVerticalScrollBar = True
        .DisplayVerticalRuler = True
        .DisplayScreenTips = False
        With .View
            .ShowAnimation = True
            .ShowPicturePlaceHolders = False
            .ShowFieldCodes = False
            .ShowBookmarks = False
            .FieldShading = wdFieldShadingAlways
            .ShowTabs = False
            .ShowSpaces = False
            .ShowParagraphs = False
            .ShowHyphens = False
            .ShowHiddenText = False
            .ShowAll = False
            .ShowDrawings = True
            .ShowObjectAnchors = True
            .ShowTextBoundaries = False
            .ShowHighlight = True
        End With
    End With
End Sub

Signature

John Doue

Ed - 03 Apr 2007 19:22 GMT
Hi John,

I don't know the whole story here but I believe the reason why the text is
turning black in 2003 is because the first piece of hidden text in the
document that the macro finds is being selected by the oRg.Select line.

In Word 97 (but I think not in 2003) comments are in some sense hidden text,
e.g. you can turn off the display of comments by unticking the Hidden text
option in Tools/Options/View.

What seems to happen in Word 97 is that if the comment comes before the
first "real" piece of hidden text then it is the comment that gets found and
selected and turns black (for me anyway). In Word 2003, because comments
aren't hidden text, the macro finds the first "real" hidden text and selects
that.

Hope this helps.

Regards.

Ed

> Hi,
>
[quoted text clipped - 81 lines]
>      End With
> End Sub
Ed - 03 Apr 2007 19:38 GMT
Hi again John,

I suspect that I mis-read your post :-] I've just spotted that in your
posting you say the problem is with Word 97.

If this is the case and if it's the text of the whole document that turns
black when there is no comment, I suspect that it is still the oRg.Select
line (selecting the whole of the ActiveDocument range).

In my copy of Word 97, with no comment, the oRg range seems to switch from
the ActiveDocument range to the "found" text range so only the found text
turns black.

Hope one or other of these posts helps :-)

Cheers.

Ed

> Hi,
>
[quoted text clipped - 81 lines]
>      End With
> End Sub
John Doue - 04 Apr 2007 08:43 GMT
> Hi again John,
>
[quoted text clipped - 100 lines]
>>      End With
>> End Sub

Thanks Ed for trying to make sense of this issue. This macro did not
cause me any problem until I had to rebuild from scratch my normal.dot
and transfer the macros. To my dismay, this problem of whole documents
ending up occasionnally selected appears not to be related to the
version of Word, since I had the problem occur on both versions since I
posted.

I have not been so far able to pinpoint which formatting causes this
unpredictable problem. But your comments might help me pinpoint the
cause, still.

Best regards

Signature

John Doue

Ed - 04 Apr 2007 18:54 GMT
Hi John,

The effect that I get here is that only the found text turns black (as
expected because it's being selected by the oRg.Select line). I saw in the
on-line help that the range does get redefined by the find (to the range of
the found text) so what I'm seeing makes sense.

As yet I have not been able to have the whole document become selected -
only the hidden text. From what you say it's as though sometimes this
redefinition of the range doesn't happen.

I'm just wondering (for lack of any better idea) whether, when you had to
redo your normal, you transferred the macros using the Organiser. If you did
then maybe the module containing the macros was itself damaged and the damage
was carried across. If that is the case, try copying the macro to a temporary
text document (e.g. in notepad), creating a new normal and pasting the
temporary text into a fresh module.

One other thought, I have seen odd behaviour when some macros are stored in
the ThisDocument container. If your macro is there then try moving it to a
standard code module.

I'm not hopeful that either of these will help but maybe somebody can
suggest a better reason for the behaviour and a cure.

Regards.

Ed

> > Hi again John,
> >
[quoted text clipped - 113 lines]
>
> Best regards
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.