D
Dayo Mitchell
Word 2001, OS 9.2.2
Help! I'm trying to get a macro to toggle between showing and hiding the
Style Width column but I can't make it work. I already had two recorded
macros for showing and hiding the Style Width column, so I modified them,
and came up with a few variations that failed to work (inept macro code
below). VB Help on If...Else...Then statements has not been helpful.
I'd like to find a method I could then apply to toggling a number of
functions (e.g. show horizontal scroll bar, show status bar). Is
If...Then...Else even the way to go?
Dayo
First Try: Sub ToggleStyleWidth()
With ActiveWindow
If .StyleAreaWidth = InchesToPoints(1.5) Then
.StyleAreaWidth = InchesToPoints(0)
With .View
Else:
If .StyleAreaWidth = InchesToPoints(0) Then
.StyleAreaWidth = InchesToPoints(1.5)
With .View
End With
End If
End Sub
But VBE keeps telling me I have an Else without an If. (As does the example
in VBA Help, by the way). Then I tried an ElseIf statement:
Sub ToggleStyleWidth()
With ActiveWindow
If .StyleAreaWidth = InchesToPoints(1.5) Then
.StyleAreaWidth = InchesToPoints(0)
With .View
ElseIf .StyleAreaWidth = InchesToPoints(0) Then
.StyleAreaWidth = InchesToPoints(1.5)
With .View
End With
End If
End Sub
And now VBE highlights the *third* ".StyleAreaWidth" and says "Compile
error: Method or data member not found." (But the others seems okay).
Help! I'm trying to get a macro to toggle between showing and hiding the
Style Width column but I can't make it work. I already had two recorded
macros for showing and hiding the Style Width column, so I modified them,
and came up with a few variations that failed to work (inept macro code
below). VB Help on If...Else...Then statements has not been helpful.
I'd like to find a method I could then apply to toggling a number of
functions (e.g. show horizontal scroll bar, show status bar). Is
If...Then...Else even the way to go?
Dayo
First Try: Sub ToggleStyleWidth()
With ActiveWindow
If .StyleAreaWidth = InchesToPoints(1.5) Then
.StyleAreaWidth = InchesToPoints(0)
With .View
Else:
If .StyleAreaWidth = InchesToPoints(0) Then
.StyleAreaWidth = InchesToPoints(1.5)
With .View
End With
End If
End Sub
But VBE keeps telling me I have an Else without an If. (As does the example
in VBA Help, by the way). Then I tried an ElseIf statement:
Sub ToggleStyleWidth()
With ActiveWindow
If .StyleAreaWidth = InchesToPoints(1.5) Then
.StyleAreaWidth = InchesToPoints(0)
With .View
ElseIf .StyleAreaWidth = InchesToPoints(0) Then
.StyleAreaWidth = InchesToPoints(1.5)
With .View
End With
End If
End Sub
And now VBE highlights the *third* ".StyleAreaWidth" and says "Compile
error: Method or data member not found." (But the others seems okay).