georgeeasten
06-13-2011, 05:27 AM
I have been using various macros which are initiated by various methods for quite some time now. I have not made any amendments to them and they work fine on other peoples computers?!?!
I have errors showing as identifier not recognised for End If, ActiveDocument.Save and Case vbNo.
The codes are as follows:
(Case vbNo)
Sub Format_Bill()
Application.ScreenUpdating = False
'*****
'Find and Replace
'*****
If ActiveDocument.Name = "04 - Bill.doc" Then
CreationDate = ActiveDocument.BuiltInDocumentProperties("Creation Date")
Select Case MsgBox("Do you want to create a formatted Bill of Costs?" & vbCrLf & vbCrLf & "Note: This may overwrite a previously formatted version", vbYesNo)
Case vbNo
'Do nothing
End
Case vbYes
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Underline = wdUnderlineNone
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p^t^t"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory
.Text = "Engaged"
.Replacement.Text = "Engaged -"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory
.Text = "% *"
.Replacement.Text = "%"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory
'*****
'delete ordinal suffix
'*****
.Text = "([0-9]{1,2})([dhnrst]{2})( [JFMASOND][anuryebchpilgstmov]{2,8} [12][0-9]{3}>)"
.Replacement.Text = "\1\3"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Selection.WholeStory
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
Selection.HomeKey Unit:=wdStory
'*****
'Change SaveAs file path
'*****
ChangeFileOpenDirectory ActiveDocument.path
Options.DefaultFilePath(wdDocumentsPath) = CurDir
'*****
'SaveAs formatted
'*****
ActiveDocument.SaveAs fileName:="04 - Bill (Formatted).doc", FileFormat:=wdFormatDocument
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
End Select
'*****
'Change SaveAs file path
'*****
ChangeFileOpenDirectory ActiveDocument.path
Options.DefaultFilePath(wdDocumentsPath) = CurDir
'*****
'SaveAs formatted
'*****
ActiveDocument.SaveAs fileName:="04 - Bill (Formatted).doc", FileFormat:=wdFormatDocument
Selection.EscapeKey
Selection.EscapeKey
Selection.EscapeKey
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
ActiveDocument.CheckGrammar
Selection.EscapeKey
Selection.EscapeKey
Selection.EscapeKey
Selection.HomeKey Unit:=wdStory
ActiveDocument.Save
End If
End Sub
(ActiveDocument.Save and End If)Sub AutoOpen()
'*****
'SpellCheck Documents
'*****
If ActiveDocument.Name = "03 - Front Sheet.doc" Then
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveDocument.CheckGrammar
ActiveDocument.Save
ElseIf ActiveDocument.Name = "08 - Schedules.doc" Then
Selection.WholeStory
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
Selection.HomeKey Unit:=wdStory
ActiveDocument.CheckGrammar
ActiveDocument.Save
ElseIf ActiveDocument.Name = "09 - Certificates.doc" Then
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.WholeStory
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
Selection.HomeKey Unit:=wdStory
ActiveDocument.CheckGrammar
ActiveDocument.Save
ElseIf ActiveDocument.Name = "10 - Back Sheet.doc" Then
ActiveDocument.CheckGrammar
ActiveDocument.Save
End If
End Sub
I am rather puzzled because it seems to have come out of nowhere and there should be no reason for it?!?!
Any help appreciated.
Thanks
I have errors showing as identifier not recognised for End If, ActiveDocument.Save and Case vbNo.
The codes are as follows:
(Case vbNo)
Sub Format_Bill()
Application.ScreenUpdating = False
'*****
'Find and Replace
'*****
If ActiveDocument.Name = "04 - Bill.doc" Then
CreationDate = ActiveDocument.BuiltInDocumentProperties("Creation Date")
Select Case MsgBox("Do you want to create a formatted Bill of Costs?" & vbCrLf & vbCrLf & "Note: This may overwrite a previously formatted version", vbYesNo)
Case vbNo
'Do nothing
End
Case vbYes
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Underline = wdUnderlineNone
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p^t^t"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory
.Text = "Engaged"
.Replacement.Text = "Engaged -"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory
.Text = "% *"
.Replacement.Text = "%"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory
'*****
'delete ordinal suffix
'*****
.Text = "([0-9]{1,2})([dhnrst]{2})( [JFMASOND][anuryebchpilgstmov]{2,8} [12][0-9]{3}>)"
.Replacement.Text = "\1\3"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Selection.WholeStory
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
Selection.HomeKey Unit:=wdStory
'*****
'Change SaveAs file path
'*****
ChangeFileOpenDirectory ActiveDocument.path
Options.DefaultFilePath(wdDocumentsPath) = CurDir
'*****
'SaveAs formatted
'*****
ActiveDocument.SaveAs fileName:="04 - Bill (Formatted).doc", FileFormat:=wdFormatDocument
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
End Select
'*****
'Change SaveAs file path
'*****
ChangeFileOpenDirectory ActiveDocument.path
Options.DefaultFilePath(wdDocumentsPath) = CurDir
'*****
'SaveAs formatted
'*****
ActiveDocument.SaveAs fileName:="04 - Bill (Formatted).doc", FileFormat:=wdFormatDocument
Selection.EscapeKey
Selection.EscapeKey
Selection.EscapeKey
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
ActiveDocument.CheckGrammar
Selection.EscapeKey
Selection.EscapeKey
Selection.EscapeKey
Selection.HomeKey Unit:=wdStory
ActiveDocument.Save
End If
End Sub
(ActiveDocument.Save and End If)Sub AutoOpen()
'*****
'SpellCheck Documents
'*****
If ActiveDocument.Name = "03 - Front Sheet.doc" Then
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveDocument.CheckGrammar
ActiveDocument.Save
ElseIf ActiveDocument.Name = "08 - Schedules.doc" Then
Selection.WholeStory
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
Selection.HomeKey Unit:=wdStory
ActiveDocument.CheckGrammar
ActiveDocument.Save
ElseIf ActiveDocument.Name = "09 - Certificates.doc" Then
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.WholeStory
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
Selection.HomeKey Unit:=wdStory
ActiveDocument.CheckGrammar
ActiveDocument.Save
ElseIf ActiveDocument.Name = "10 - Back Sheet.doc" Then
ActiveDocument.CheckGrammar
ActiveDocument.Save
End If
End Sub
I am rather puzzled because it seems to have come out of nowhere and there should be no reason for it?!?!
Any help appreciated.
Thanks