1

Тема: Общая форма для просмотра свойств Класса

В данной теме рассказываю о создании простой формы пользователя для просмотра свойств какого-либо Класса.
Для начала создадим пользовательскую форму UserForm в редакторе VBA, для этого в шаблоне Normal создайте новую форму.

Общая форма для просмотра свойств Класса

В окне Properties задайте следующие свойства формы:
1. Name - form_ClassInfo (уникальное имя формы)
2. Height - 400 (высота формы)
3. Width - 300 (ширина формы)
4. ShowModal - False (при ShowModal = False, Активный документ доступен для редактирования,  при ShowModal = True Активный документ доступен для редактирования только после закрытия формы.

Post's attachments

002.jpg
002.jpg 115.45 Кб, 2 скачиваний с 2012-05-17 

You don't have the permssions to download the attachments of this post.

2

Re: Общая форма для просмотра свойств Класса

Далее на созданной форме создаем элементы управления как показано на рисунке
Общая форма для просмотра свойств Класса
Файл формы на данном этапе вложен в следующем посте

Post's attachments

003.jpg
003.jpg 183.68 Кб, 2 скачиваний с 2012-05-17 

You don't have the permssions to download the attachments of this post.

3

Re: Общая форма для просмотра свойств Класса

Для вставки формы в Ваш проект разархивируйте вложенный архив в какую-нибудь папку.
Откройте редактор VBA, выберете проект Normal, выведете правым кликом всплывающее меню и выберете ImportFile. Укажите путь к разархивированному файлу с расширением .frm

Post's attachments

form_ClassInfo.rar 1.55 Кб, 1 скачиваний с 2012-05-17 

You don't have the permssions to download the attachments of this post.

4

Re: Общая форма для просмотра свойств Класса

После создания интерфейса формы откроем окно кода формы и создадим свойство Unit(Единица измерения), для радиокнопок находящихся в  рамке «Единицы измерения» события Chenge

Public Unit As WdMeasurementUnits

Private Sub opb_Lines_Change()
    If Me.opb_Lines.Value = True Then
        Me.Unit = wdPicas
    End If
End Sub

Private Sub opb_UnitApplication_Change()
    If Me.opb_UnitApplication.Value = True Then
        Me.Unit = ThisDocument.Application.Options.MeasurementUnit
    End If
End Sub

Private Sub opb_UnitCentimeters_Change()
    If Me.opb_UnitCentimeters.Value = True Then
        Me.Unit = wdCentimeters
    End If
End Sub

Private Sub opb_UnitInches_Change()
    If Me.opb_UnitInches.Value = True Then
        Me.Unit = wdInches
    End If
End Sub

Private Sub opb_UnitMillimeters_Change()
    If Me.opb_UnitMillimeters.Value = True Then
        Me.Unit = wdMillimeters
    End If
End Sub

Private Sub opb_UnitPicas_Change()
    If Me.opb_UnitPicas.Value = True Then
        Me.Unit = wdPicas
    End If
End Sub

Private Sub opb_UnitPoints_Change()
    If Me.opb_UnitPoints.Value = True Then
        Me.Unit = wdPoints
    End If
End Sub

Отредактировано aap77 (17.05.2012 20:04:22)

5

Re: Общая форма для просмотра свойств Класса

Далее создадим функцию  перевода единиц измерения в зависимости от свойства Unit:

Public Function Value(Num As Variant) As Single
    If Me.Unit = wdInches Then
        Value = PointsToInches(Num)
        Exit Function
    ElseIf Me.Unit = wdCentimeters Then
        Value = PointsToCentimeters(Num)
        Exit Function
    ElseIf Me.Unit = wdMillimeters Then
        Value = PointsToMillimeters(Num)
        Exit Function
    ElseIf Me.Unit = wdPoints Then
        Value = Num
        Exit Function
    ElseIf Me.Unit = wdPicas Then
        Value = PointsToPicas(Num)
        Exit Function
    End If
End Function

6

Re: Общая форма для просмотра свойств Класса

Теперь создадим свойство Info в котором будет содержаться текст выводимой информации.

Общий код для созданной нами формы будет выглядеть так:
Public Unit As WdMeasurementUnits

Dim Info As String

Private Sub opb_Lines_Change()
    If Me.opb_Lines.Value = True Then
        Me.Unit = wdPicas
    End If
End Sub

Private Sub opb_UnitApplication_Change()
    If Me.opb_UnitApplication.Value = True Then
        Me.Unit = ThisDocument.Application.Options.MeasurementUnit
    End If
End Sub

Private Sub opb_UnitCentimeters_Change()
    If Me.opb_UnitCentimeters.Value = True Then
        Me.Unit = wdCentimeters
    End If
End Sub

Private Sub opb_UnitInches_Change()
    If Me.opb_UnitInches.Value = True Then
        Me.Unit = wdInches
    End If
End Sub

Private Sub opb_UnitMillimeters_Change()
    If Me.opb_UnitMillimeters.Value = True Then
        Me.Unit = wdMillimeters
    End If
End Sub

Private Sub opb_UnitPicas_Change()
    If Me.opb_UnitPicas.Value = True Then
        Me.Unit = wdPicas
    End If
End Sub

Private Sub opb_UnitPoints_Change()
    If Me.opb_UnitPoints.Value = True Then
        Me.Unit = wdPoints
    End If
End Sub

Public Function Value(Num As Variant) As Single
    If Me.Unit = wdInches Then
        Value = PointsToInches(Num)
        Exit Function
    ElseIf Me.Unit = wdCentimeters Then
        Value = PointsToCentimeters(Num)
        Exit Function
    ElseIf Me.Unit = wdMillimeters Then
        Value = PointsToMillimeters(Num)
        Exit Function
    ElseIf Me.Unit = wdPoints Then
        Value = Num
        Exit Function
    ElseIf Me.Unit = wdPicas Then
        Value = PointsToPicas(Num)
        Exit Function
    End If
End Function

Во вложении находится файл созданной формы

Отредактировано aap77 (17.05.2012 21:08:37)

Post's attachments

form_ClassInfo.rar 1.85 Кб, 4 скачиваний с 2012-05-17 

You don't have the permssions to download the attachments of this post.

7

Re: Общая форма для просмотра свойств Класса

Ну