不会吧,我又看了一次代码,应该没有问题。 以下是该程序代码,供参考: Public Pe As Integer
Private Sub ComboBox1_Change()
If ComboBox1.ListCount = 0 Then
CommandButton1.Enabled = False
Exit Sub
ElseIf ComboBox1.ListIndex + 1 > Pe Or ComboBox1.ListIndex + 1 < 1 Then
MsgBox "无效页码!"
CommandButton1.Enabled = False
Else
CommandButton1.Enabled = True
End If
End Sub Private Sub ComboBox2_Change()
If ComboBox1.ListCount = 0 Then
CommandButton1.Enabled = False
Exit Sub
ElseIf ComboBox1.ListIndex + 1 > Pe Or ComboBox1.ListIndex + 1 < 1 Then
MsgBox "无效页码!"
CommandButton1.Enabled = False
Else
CommandButton1.Enabled = True
End If
End Sub Private Sub CommandButton1_Click()
Dim RangeStart As Long, RangeEnd As Long
With ActiveDocument
.Range(0, 0).Select
If ComboBox1.ListIndex + 1 = ComboBox2.ListIndex + 1 Then
If ComboBox2.ListIndex + 1 = Pe Then
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=Me.ComboBox2.ListIndex + 1
RangeStart = Selection.Range.Start
RangeEnd = .Content.End
Else
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=Me.ComboBox1.ListIndex + 1
RangeStart = Selection.Range.Start
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=Me.ComboBox1.ListIndex + 2
RangeEnd = Selection.Range.Start
End If
ElseIf ComboBox1.ListIndex + 1 = Pe Then
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=Me.ComboBox2.ListIndex + 1
RangeStart = Selection.Range.Start
RangeEnd = .Content.End
ElseIf ComboBox2.ListIndex + 1 = Pe Then
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=Me.ComboBox1.ListIndex + 1
RangeStart = Selection.Range.Start
RangeEnd = .Content.End
ElseIf ComboBox1.ListIndex + 1 > ComboBox2.ListIndex + 1 Then
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=Me.ComboBox2.ListIndex + 1
RangeStart = Selection.Range.Start
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=Me.ComboBox1.ListIndex + 2
RangeEnd = Selection.Range.Start
Else
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=Me.ComboBox1.ListIndex + 1
RangeStart = Selection.Range.Start
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=Me.ComboBox2.ListIndex + 2
RangeEnd = Selection.Range.Start
End If
.Range(RangeStart, RangeEnd).Select
End With
End Sub Private Sub UserForm_Activate()
Dim i As Integer
CommandButton1.Enabled = fasle
Pe = Selection.Information(wdNumberOfPagesInDocument)
For i = 1 To Pe
Me.ComboBox1.AddItem i
Me.ComboBox2.AddItem i
Next
End Sub |