can someone tell me why i m facing this error

D

Designingsally

hi i dont knw why i m encoutering this error. I dont even know if its only me
who is facing this error. this macro highlights - and then it changes the
letter preceding - to lower case. This has been discussed previosly in this
forum. It was working fine till few days back. Now i m facing some new
problem, which has put me in a dilemma. pls guide me thru this. I dont y i m
facing this problem
sample data
Demonstration Screen – Format 1
Demonstration Screen – Format 2
Practice Screen – Format 1 Quiz Screens
Match the Following - Text
Match the Following - Graphics
Sequencing - Text
Sequencing - Graphics
Fill in the Blank
True or False
Hot Spot
Multiple Choice Question - Text (Single Select / Multiple Select)
Multiple Choice Question - Graphics (Single Select / Multiple Select)


Well.. demonstration screen is not highlighted which is correct so is
sequencing which is correct again. but multiple choice question is match the
following is been
highlighted why, they shd not be highlighted.

the macro i have used is

Private Sub Hyphn()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
..HomeKey wdStory
With .FInd
..ClearFormatting
..Replacement.ClearFormatting
Do While .Execute("- [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Demonstration Screen – ") = False Then
If InStr(1, preRng.Text, "Sequencing - ") = False Then
If InStr(1, preRng.Text, "Multiple Choice Question - ") = False Then
If InStr(1, preRng.Text, "Match Choice Question -") = False Then
If InStr(1, preRng.Text, "Practice Screen - ") = False Then
If InStr(1, preRng.Text, "Match the Following - ") = False Then

sCase = Msgbox("Word after colon should be in lower case.Change?",
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
End If
End If
End If
End If
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
 
P

Pesach Shelnitz

Hi Sally,

Your macros are getting better and better, but you have to watch out for
those little details.

1) Your macro has an error that prevents it from running. You declare one of
your Range objects with the name orng, but you have a line that begins with
Set myRange. This probably happened because you copied pieces of macros
written by different people. In this case, just change myRange to orng in
that line, or change orng to myRange everywhere else.

2) Your preRng range is extended by 3 words. This is not enough to include
your test strings that contain three words. You need to extend it by 5 words.
This is why the three-word expression "Multiple Choice Question" is not
found. Change

preRng.MoveStart wdWord, -3

to

preRng.MoveStart wdWord, -5

3) The Instr function
(http://msdn.microsoft.com/en-us/library/wybb344c(VS.85).aspx) would return
0, not False, when the string in quotes in not found. For this reason, you
should replace False with 0 in the If statements containg Instr. This won't
change how the macro works because VBA handles this coding error, but it will
make me happy to see you learning to do things with greater precision.

4) In your test text, some of the hyphens have already been replaced by an
en dash. These strings will not be found by the initial search. Is this how
you want things to be?

5) Since you copied the en dashes mentioned in 4) into the strings in the
calls to Instr, you will get incorrect results if the type of hyphen in the
text doesn't match the type of hyphen in your code. For this reason, I
suggest that you remove the terminating spaces and hyphens in these calls.
For example, change

InStr(1, preRng.Text, "Demonstration Screen – ")

to

InStr(1, preRng.Text, "Demonstration Screen")


6) In the message, you should change "colon" to "hyphen".

--
Hope this helps,
Pesach Shelnitz


Designingsally said:
hi i dont knw why i m encoutering this error. I dont even know if its only me
who is facing this error. this macro highlights - and then it changes the
letter preceding - to lower case. This has been discussed previosly in this
forum. It was working fine till few days back. Now i m facing some new
problem, which has put me in a dilemma. pls guide me thru this. I dont y i m
facing this problem
sample data
Demonstration Screen – Format 1
Demonstration Screen – Format 2
Practice Screen – Format 1 Quiz Screens
Match the Following - Text
Match the Following - Graphics
Sequencing - Text
Sequencing - Graphics
Fill in the Blank
True or False
Hot Spot
Multiple Choice Question - Text (Single Select / Multiple Select)
Multiple Choice Question - Graphics (Single Select / Multiple Select)


Well.. demonstration screen is not highlighted which is correct so is
sequencing which is correct again. but multiple choice question is match the
following is been
highlighted why, they shd not be highlighted.

the macro i have used is

Private Sub Hyphn()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("- [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Demonstration Screen – ") = False Then
If InStr(1, preRng.Text, "Sequencing - ") = False Then
If InStr(1, preRng.Text, "Multiple Choice Question - ") = False Then
If InStr(1, preRng.Text, "Match Choice Question -") = False Then
If InStr(1, preRng.Text, "Practice Screen - ") = False Then
If InStr(1, preRng.Text, "Match the Following - ") = False Then

sCase = Msgbox("Word after colon should be in lower case.Change?",
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
End If
End If
End If
End If
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
 
D

Doug Robbins - Word MVP

Please read what you are about to post before sending it and correct it.

In the case of

Match the Following - Text
Match the Following - Graphics
Multiple Choice Question - Text (Single Select / Multiple Select)
Multiple Choice Question - Graphics (Single Select / Multiple Select)

after the command

preRng.MoveStart wdWord, -3

is executed, preRng contains the following

the Following - T
the Following - G
Choice Question - T
Choice Question - G

respectively.

As a result, all of your If Instr() commands return False and the following
command executes:

sCase = Msgbox("Word after colon should be in lower case.Change?", _
vbYesNoCancel, "Change Case")

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Designingsally said:
hi i dont knw why i m encoutering this error. I dont even know if its only
me
who is facing this error. this macro highlights - and then it changes the
letter preceding - to lower case. This has been discussed previosly in
this
forum. It was working fine till few days back. Now i m facing some new
problem, which has put me in a dilemma. pls guide me thru this. I dont y i
m
facing this problem
sample data
Demonstration Screen – Format 1
Demonstration Screen – Format 2
Practice Screen – Format 1 Quiz Screens
Match the Following - Text
Match the Following - Graphics
Sequencing - Text
Sequencing - Graphics
Fill in the Blank
True or False
Hot Spot
Multiple Choice Question - Text (Single Select / Multiple Select)
Multiple Choice Question - Graphics (Single Select / Multiple Select)


Well.. demonstration screen is not highlighted which is correct so is
sequencing which is correct again. but multiple choice question is match
the
following is been
highlighted why, they shd not be highlighted.

the macro i have used is

Private Sub Hyphn()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("- [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Demonstration Screen – ") = False Then
If InStr(1, preRng.Text, "Sequencing - ") = False Then
If InStr(1, preRng.Text, "Multiple Choice Question - ") = False Then
If InStr(1, preRng.Text, "Match Choice Question -") = False Then
If InStr(1, preRng.Text, "Practice Screen - ") = False Then
If InStr(1, preRng.Text, "Match the Following - ") = False Then

If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
End If
End If
End If
End If
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
 
D

Designingsally

thanks for the reply
--
I believe in Hope.

DesigningSally


Doug Robbins - Word MVP said:
Please read what you are about to post before sending it and correct it.

In the case of

Match the Following - Text
Match the Following - Graphics
Multiple Choice Question - Text (Single Select / Multiple Select)
Multiple Choice Question - Graphics (Single Select / Multiple Select)

after the command

preRng.MoveStart wdWord, -3

is executed, preRng contains the following

the Following - T
the Following - G
Choice Question - T
Choice Question - G

respectively.

As a result, all of your If Instr() commands return False and the following
command executes:

sCase = Msgbox("Word after colon should be in lower case.Change?", _
vbYesNoCancel, "Change Case")

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Designingsally said:
hi i dont knw why i m encoutering this error. I dont even know if its only
me
who is facing this error. this macro highlights - and then it changes the
letter preceding - to lower case. This has been discussed previosly in
this
forum. It was working fine till few days back. Now i m facing some new
problem, which has put me in a dilemma. pls guide me thru this. I dont y i
m
facing this problem
sample data
Demonstration Screen – Format 1
Demonstration Screen – Format 2
Practice Screen – Format 1 Quiz Screens
Match the Following - Text
Match the Following - Graphics
Sequencing - Text
Sequencing - Graphics
Fill in the Blank
True or False
Hot Spot
Multiple Choice Question - Text (Single Select / Multiple Select)
Multiple Choice Question - Graphics (Single Select / Multiple Select)


Well.. demonstration screen is not highlighted which is correct so is
sequencing which is correct again. but multiple choice question is match
the
following is been
highlighted why, they shd not be highlighted.

the macro i have used is

Private Sub Hyphn()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("- [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Demonstration Screen – ") = False Then
If InStr(1, preRng.Text, "Sequencing - ") = False Then
If InStr(1, preRng.Text, "Multiple Choice Question - ") = False Then
If InStr(1, preRng.Text, "Match Choice Question -") = False Then
If InStr(1, preRng.Text, "Practice Screen - ") = False Then
If InStr(1, preRng.Text, "Match the Following - ") = False Then

If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
End If
End If
End If
End If
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
 
D

Designingsally

thanks for the reply
--
I believe in Hope.

DesigningSally


Pesach Shelnitz said:
Hi Sally,

Your macros are getting better and better, but you have to watch out for
those little details.

1) Your macro has an error that prevents it from running. You declare one of
your Range objects with the name orng, but you have a line that begins with
Set myRange. This probably happened because you copied pieces of macros
written by different people. In this case, just change myRange to orng in
that line, or change orng to myRange everywhere else.

2) Your preRng range is extended by 3 words. This is not enough to include
your test strings that contain three words. You need to extend it by 5 words.
This is why the three-word expression "Multiple Choice Question" is not
found. Change

preRng.MoveStart wdWord, -3

to

preRng.MoveStart wdWord, -5

3) The Instr function
(http://msdn.microsoft.com/en-us/library/wybb344c(VS.85).aspx) would return
0, not False, when the string in quotes in not found. For this reason, you
should replace False with 0 in the If statements containg Instr. This won't
change how the macro works because VBA handles this coding error, but it will
make me happy to see you learning to do things with greater precision.

4) In your test text, some of the hyphens have already been replaced by an
en dash. These strings will not be found by the initial search. Is this how
you want things to be?

5) Since you copied the en dashes mentioned in 4) into the strings in the
calls to Instr, you will get incorrect results if the type of hyphen in the
text doesn't match the type of hyphen in your code. For this reason, I
suggest that you remove the terminating spaces and hyphens in these calls.
For example, change

InStr(1, preRng.Text, "Demonstration Screen – ")

to

InStr(1, preRng.Text, "Demonstration Screen")


6) In the message, you should change "colon" to "hyphen".

--
Hope this helps,
Pesach Shelnitz


Designingsally said:
hi i dont knw why i m encoutering this error. I dont even know if its only me
who is facing this error. this macro highlights - and then it changes the
letter preceding - to lower case. This has been discussed previosly in this
forum. It was working fine till few days back. Now i m facing some new
problem, which has put me in a dilemma. pls guide me thru this. I dont y i m
facing this problem
sample data
Demonstration Screen – Format 1
Demonstration Screen – Format 2
Practice Screen – Format 1 Quiz Screens
Match the Following - Text
Match the Following - Graphics
Sequencing - Text
Sequencing - Graphics
Fill in the Blank
True or False
Hot Spot
Multiple Choice Question - Text (Single Select / Multiple Select)
Multiple Choice Question - Graphics (Single Select / Multiple Select)


Well.. demonstration screen is not highlighted which is correct so is
sequencing which is correct again. but multiple choice question is match the
following is been
highlighted why, they shd not be highlighted.

the macro i have used is

Private Sub Hyphn()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("- [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Demonstration Screen – ") = False Then
If InStr(1, preRng.Text, "Sequencing - ") = False Then
If InStr(1, preRng.Text, "Multiple Choice Question - ") = False Then
If InStr(1, preRng.Text, "Match Choice Question -") = False Then
If InStr(1, preRng.Text, "Practice Screen - ") = False Then
If InStr(1, preRng.Text, "Match the Following - ") = False Then

sCase = Msgbox("Word after colon should be in lower case.Change?",
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
End If
End If
End If
End If
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
 
D

Designingsally

thanks for taking efforts for explaining the whole concept beautifully :)
--
I believe in Hope.

DesigningSally


Pesach Shelnitz said:
Hi Sally,

Your macros are getting better and better, but you have to watch out for
those little details.

1) Your macro has an error that prevents it from running. You declare one of
your Range objects with the name orng, but you have a line that begins with
Set myRange. This probably happened because you copied pieces of macros
written by different people. In this case, just change myRange to orng in
that line, or change orng to myRange everywhere else.

2) Your preRng range is extended by 3 words. This is not enough to include
your test strings that contain three words. You need to extend it by 5 words.
This is why the three-word expression "Multiple Choice Question" is not
found. Change

preRng.MoveStart wdWord, -3

to

preRng.MoveStart wdWord, -5

3) The Instr function
(http://msdn.microsoft.com/en-us/library/wybb344c(VS.85).aspx) would return
0, not False, when the string in quotes in not found. For this reason, you
should replace False with 0 in the If statements containg Instr. This won't
change how the macro works because VBA handles this coding error, but it will
make me happy to see you learning to do things with greater precision.

4) In your test text, some of the hyphens have already been replaced by an
en dash. These strings will not be found by the initial search. Is this how
you want things to be?

5) Since you copied the en dashes mentioned in 4) into the strings in the
calls to Instr, you will get incorrect results if the type of hyphen in the
text doesn't match the type of hyphen in your code. For this reason, I
suggest that you remove the terminating spaces and hyphens in these calls.
For example, change

InStr(1, preRng.Text, "Demonstration Screen – ")

to

InStr(1, preRng.Text, "Demonstration Screen")


6) In the message, you should change "colon" to "hyphen".

--
Hope this helps,
Pesach Shelnitz


Designingsally said:
hi i dont knw why i m encoutering this error. I dont even know if its only me
who is facing this error. this macro highlights - and then it changes the
letter preceding - to lower case. This has been discussed previosly in this
forum. It was working fine till few days back. Now i m facing some new
problem, which has put me in a dilemma. pls guide me thru this. I dont y i m
facing this problem
sample data
Demonstration Screen – Format 1
Demonstration Screen – Format 2
Practice Screen – Format 1 Quiz Screens
Match the Following - Text
Match the Following - Graphics
Sequencing - Text
Sequencing - Graphics
Fill in the Blank
True or False
Hot Spot
Multiple Choice Question - Text (Single Select / Multiple Select)
Multiple Choice Question - Graphics (Single Select / Multiple Select)


Well.. demonstration screen is not highlighted which is correct so is
sequencing which is correct again. but multiple choice question is match the
following is been
highlighted why, they shd not be highlighted.

the macro i have used is

Private Sub Hyphn()
Dim orng As Range
Dim preRng As Range
Dim sCase As String
Set myRange = ActiveDocument.Range
With Selection
.HomeKey wdStory
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("- [A-Z]", MatchWildcards:=True)
Set orng = Selection.Range
orng.Start = orng.End - 1
orng.Select
Set preRng = Selection.Range
preRng.MoveStart wdWord, -3
'MsgBox preRng.Text
If InStr(1, preRng.Text, "Demonstration Screen – ") = False Then
If InStr(1, preRng.Text, "Sequencing - ") = False Then
If InStr(1, preRng.Text, "Multiple Choice Question - ") = False Then
If InStr(1, preRng.Text, "Match Choice Question -") = False Then
If InStr(1, preRng.Text, "Practice Screen - ") = False Then
If InStr(1, preRng.Text, "Match the Following - ") = False Then

sCase = Msgbox("Word after colon should be in lower case.Change?",
vbYesNoCancel, "Change Case")
If sCase = vbCancel Then
Exit Sub
End If
If sCase = vbYes Then orng.Case = wdLowerCase
End If
End If
End If
End If
End If
End If
Selection.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
 

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