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

J

John Doue

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
 
E

Ed

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
 
E

Ed

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
 
J

John Doue

Ed said:
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

John Doue said:
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
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
 
E

Ed

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

John Doue said:
Ed said:
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

John Doue said:
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
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top