Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable AutoFormat with VBA in Word 2000 and XP 1

Status
Not open for further replies.

ACH381

Technical User
Apr 3, 2002
49
US
How can I disable AutoFormat and AutoCorrect using VBA in Word XP and 2000? I can disable it and re-enable it in just XP or just 2000, but not both. My problem is this - I am building an application in Word that will be used in both Word 2000 and Word XP (versions 9 and 10). There are 4 extra attributes in the AutoFormat (AF) dialog box in XP than there are in 2000. I have written a script that saves the settings for each AF attribute in an Array before my script disables all of them. Then during the close routine I call a sub that reads the array and sets everything back to the way it was when I launched the program. Because of the 4 extra attributes in XP, Word 2000 VBA won't compile when the program opens. I get a compile error because the script is referencing 4 attributes that are in the script for XP but are not located in 2000. I tried trapping out the 4 attributes by putting them in an IF-Then statement, but the compiler ignores the fact that the attributes are in the If-Then statement and blows up anyway.
 
Why not posting your code to help us help you ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi ACH381,

You can check the Application.Version property and then use CallByName. That way the compiler won't check the property names you are using, for example ...
Code:
[blue]If Application.Version >= 10 then
    CallByName Application.AutoCorrect, "CorrectTableCells", vbLet, False
End If[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
As requested here are my current scripts. They are a little long and cumbersome, so if anyone has an easier way to do this, please let me know.

Global AF(45) 'AutoFormat Default Array

Private Sub Document_Open()
GetAutoFormatDefault
DisableAutoFormat
End Sub

‘This stores the user’s AutoFormat settings in a Global Variable AF before the application disables everything
Sub GetAutoFormatDefault()
On Error Resume Next
With AutoCorrect
AF(0) = .FirstLetterAutoAdd
AF(1) = .TwoInitialCapsAutoAdd
AF(2) = .OtherCorrectionsAutoAdd
AF(3) = .CorrectInitialCaps
AF(4) = .CorrectSentenceCaps
AF(5) = .CorrectDays
AF(6) = .CorrectCapsLock
AF(7) = .ReplaceText
AF(8) = .ReplaceTextFromSpellingChecker
AF(9) = .CorrectKeyboardSetting
AF(10) = .DisplayAutoCorrectOptions ‘XP Only
'AF(11) = .CorrectTableCells ‘XP Only
End With
AF(12) = Application.DisplayAutoCompleteTips
With Options
AF(13) = .AutoFormatApplyHeadings
AF(14) = .AutoFormatApplyLists
AF(15) = .AutoFormatApplyBulletedLists
AF(16) = .AutoFormatApplyOtherParas
AF(17) = .AutoFormatReplaceQuotes
AF(18) = .AutoFormatReplaceSymbols
AF(19) = .AutoFormatReplaceOrdinals
AF(20) = .AutoFormatReplaceFractions
AF(21) = .AutoFormatReplacePlainTextEmphasis
AF(22) = .AutoFormatReplaceHyperlinks
AF(23) = .AutoFormatPreserveStyles
AF(24) = .AutoFormatPlainTextWordMail
AF(25) = .LabelSmartTags ‘XP Only
AF(26) = .DisplaySmartTagButtons ‘XP Only
AF(27) = .AutoFormatAsYouTypeApplyHeadings
AF(28) = .AutoFormatAsYouTypeApplyBorders
AF(29) = .AutoFormatAsYouTypeApplyBulletedLists
AF(30) = .AutoFormatAsYouTypeApplyNumberedLists
AF(31) = .AutoFormatAsYouTypeApplyTables
AF(32) = .AutoFormatAsYouTypeReplaceQuotes
AF(33) = .AutoFormatAsYouTypeReplaceSymbols
AF(34) = .AutoFormatAsYouTypeReplaceOrdinals
AF(35) = .AutoFormatAsYouTypeReplaceFractions
AF(36) = .AutoFormatAsYouTypeReplacePlainTextEmphasis
AF(37) = .AutoFormatAsYouTypeReplaceHyperlinks
AF(38) = .AutoFormatAsYouTypeFormatListItemBeginning
AF(39) = .AutoFormatAsYouTypeDefineStyles
AF(40) = .TabIndentKey = True
End With
AF(41) = Selection.Document.Kind
End Sub


‘This disables the AutoFormat
Sub DisableAutoFormat()
On Error Resume Next
With AutoCorrect
.CorrectInitialCaps = False
.CorrectSentenceCaps = False
.CorrectDays = False
.CorrectCapsLock = False
.ReplaceText = False
.ReplaceTextFromSpellingChecker = True
.CorrectKeyboardSetting = False
.CorrectTableCells = False ‘XP Only
.DisplayAutoCorrectOptions = False ‘XP Only
End With
With Options
.AutoFormatAsYouTypeApplyHeadings = False
.AutoFormatAsYouTypeApplyBorders = False
.AutoFormatAsYouTypeApplyBulletedLists = False
.AutoFormatAsYouTypeApplyNumberedLists = False
.AutoFormatAsYouTypeApplyTables = False
.AutoFormatAsYouTypeReplaceQuotes = True
.AutoFormatAsYouTypeReplaceSymbols = False
.AutoFormatAsYouTypeReplaceOrdinals = False
.AutoFormatAsYouTypeReplaceFractions = False
.AutoFormatAsYouTypeReplacePlainTextEmphasis = False
.AutoFormatAsYouTypeReplaceHyperlinks = False
.AutoFormatAsYouTypeFormatListItemBeginning = False
.AutoFormatAsYouTypeDefineStyles = False
End With
Application.DisplayAutoCompleteTips = False
With Options
.AutoFormatApplyHeadings = False
.AutoFormatApplyLists = False
.AutoFormatApplyBulletedLists = False
.AutoFormatApplyOtherParas = False
.AutoFormatReplaceQuotes = True
.AutoFormatReplaceSymbols = False
.AutoFormatReplaceOrdinals = False
.AutoFormatReplaceFractions = False
.AutoFormatReplacePlainTextEmphasis = False
.AutoFormatReplaceHyperlinks = False
.AutoFormatPreserveStyles = True
.AutoFormatPlainTextWordMail = False
.LabelSmartTags = False ‘XP Only
.DisplaySmartTagButtons = False ‘XP Only
End With
End Sub


‘This resets AutoFormat to how the user had it when the application was opened.
Sub ResetAutoFormat()
With AutoCorrect
.FirstLetterAutoAdd = AF(0)
.TwoInitialCapsAutoAdd = AF(1)
.OtherCorrectionsAutoAdd = AF(2)
.CorrectInitialCaps = AF(3)
.CorrectSentenceCaps = AF(4)
.CorrectDays = AF(5)
.CorrectCapsLock = AF(6)
.ReplaceText = AF(7)
.ReplaceTextFromSpellingChecker = AF(8)
.CorrectKeyboardSetting = AF(9)
.DisplayAutoCorrectOptions = AF(10) ‘XP Only
.CorrectTableCells = AF(11) ‘XP Only
End With
Application.DisplayAutoCompleteTips = AF(12)
With Options
.AutoFormatApplyHeadings = AF(13)
.AutoFormatApplyLists = AF(14)
.AutoFormatApplyBulletedLists = AF(15)
.AutoFormatApplyOtherParas = AF(16)
.AutoFormatReplaceQuotes = AF(17)
.AutoFormatReplaceSymbols = AF(18)
.AutoFormatReplaceOrdinals = AF(19)
.AutoFormatReplaceFractions = AF(20)
.AutoFormatReplacePlainTextEmphasis = AF(21)
.AutoFormatReplaceHyperlinks = AF(22)
.AutoFormatPreserveStyles = AF(23)
.AutoFormatPlainTextWordMail = AF(24)
.LabelSmartTags = AF(25) ‘XP Only
.DisplaySmartTagButtons = AF(26) ‘XP Only
.AutoFormatAsYouTypeApplyHeadings = AF(27)
.AutoFormatAsYouTypeApplyBorders = AF(28)
.AutoFormatAsYouTypeApplyBulletedLists = AF(29)
.AutoFormatAsYouTypeApplyNumberedLists = AF(30)
.AutoFormatAsYouTypeApplyTables = AF(31)
.AutoFormatAsYouTypeReplaceQuotes = AF(32)
.AutoFormatAsYouTypeReplaceSymbols = AF(33)
.AutoFormatAsYouTypeReplaceOrdinals = AF(34)
.AutoFormatAsYouTypeReplaceFractions = AF(35)
.AutoFormatAsYouTypeReplacePlainTextEmphasis = AF(36)
.AutoFormatAsYouTypeReplaceHyperlinks = AF(37)
.AutoFormatAsYouTypeFormatListItemBeginning = AF(38)
.AutoFormatAsYouTypeDefineStyles = AF(39)
.TabIndentKey = AF(40)
End With
AF(41) = Selection.Document.Kind
End Sub


Sub DuringClose()
ResetAutoFormat
End Sub
 
To clarify, ..

Replace
Code:
[purple]AF(10) = .DisplayAutoCorrectOptions    ‘XP Only[/purple]
WIth
Code:
[blue]If Application.Version >= 10 Then 
    AF(10) = CallByName(Application.AutoCorrect, "DisplayAutoCorrectOptions", vbGet)
End If[/blue]
and similar constructs elsewhere.

And may I just say that I heartily approve of you remembering User settings. Far too often programmers play fast and loose with them.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Thank you for the help. I'll give it a shot tonight.
Allan
 
Tony
The CallByName procedure worked great. It took me a little bit to work out the syntax for resetting using vbLet, so here is the syntax in case anyone else needs to use it.

This fills the array with the current setting of the attribute:
If Application.Version >= 10 Then
AF(10) = CallByName (Application.AutoCorrect, "DisplayAutoCorrectOptions", VbGet)
End If

This sets the attribute to false
If Application.Version >= 10 Then
CallByName Application.AutoCorrect, "DisplayAutoCorrectOptions", VbLet, False
End If

This resets the attribute with the contents of the array
If Application.Version >= 10 Then
CallByName Application.AutoCorrect, "DisplayAutoCorrectOptions", VbLet, AF(10)
End if

Thanks again
Allan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top