Интернет-журнал 'Домашняя лаборатория', 2007 №3 - Вудворт
Шрифт:
Интервал:
Закладка:
����� ������ �� ������ ���������� Office � ������ ����� ������������ ���������� ActiveX. ��� �������� �� ��������� � Office ����������� ������������ ���� ��������� � ������ ��� ����� ������, � ������� ����� �������� ���� �� ���������, ��� ������������ ��� ���������������� ������ � ���� ����������. ���, ����� ����� ���� �� Word'oBCKoro ������� �������� � Excel'��, ������� ������� ������ "Excel.Sheet":
�
Dim es As Object
Set es = CreateObject("Excel.Sheet")
����� "es" � ������� ������������ ����������, ����� ���� �����.
(���� ���� ����� ������� �����-���� ���� Excel'�, �� ����� ������������ ������� "GetObject":
Set es= GetObject("���� � ����� Excel'a"))
��� ������� ����� ������� ��������� ������ Excel �������:
es.Application.Visible = True
������ ����� ����� ������� es (�.��. ������ ����������� Excel'�) �������� ������� ����� ��, ��� � � �������� Excel'a (��������� ������� "es.Application." �� �� ������, ������� �� ������� ������� �������� �������,�� ��� ��� ���� ���� ������ ���������, ��� ������ ���� ������ � Excel' ��). ���, ����� ������� ���� Excel'a, ����� ����� ���� ������� es.Application.Workbooks.Open FileName:="���� � ��������� Excel'a" � �����, ��������, ��������� � ������ ������ �������� ����� �����, ����������� �������
es.Cells(1, 1).Value = "��� ������� �, ������ 1"
������� Excel ����� ��������
es.Application.Quit
Set es = Nothing
����� ���� ������� �� ���������� ������, ������������ � ����� Excel. ��� ����� ������� ������������ �������
es.Application.Run "��� �������"
��� ��� ���� ������� ��� ����������.
ProgressBar � ����� ������������ ������ ���������� ��� Windows ������������ ����� �������, ��� ProgressBar � ���������, ������������, �� ������� ����������� ��� ��� ���� �������. � ���������, �� ���� ����������� �� ���� ����������-�������������. � ���������, � VBA ���� ������� �����������, �� ��� ����� ������� ��������������!
��������� �� �����, ��������, ���, ��� �� ���.�5.3.
���.�5.3. ProgressBar � ��������� �� VBA
� �������� �� ��������� ������� (��������������, ��� � ��� ���� ����� ���������, � ������� ����������� ������� � ������ ����: �� ���� ��������� ��� ���������� ��������� ���������� ��������, � ������� ���� �������� ProgressBar'��):
1.�������� ��������� ����� � �������� �� ���: ������� � ������������� ������� (��������, "Label1") � ��� ������ �������, (������, "Label2" � "Label3"), ������ � �������, ������� ���������� ���� ��� ������ (���.�5.4).
���.�5.4. � ��� ��� �� ������
� �������, �� ���������� � �������:
Label2: ��� � 45, Left � 15, Height � 15, Width � 250
Label3: Top � 45, Left � 15, Height � 15, Width � 0
������� � �������� �������� ����� ��� "Label2" � �����, � ��� "Label3" � ������� (�������� "BackColor", ������� "�������").
2.���� ����, ����� ����� ��������� �� ������, �� ����� ���� ������������� ���������� ��� ����� ������ �����������, � �� ��� ����� ��������� ��������� �����:
Private Sub UserForm_Activate()
� ��������� ����� ���������, ������� ������ ����������� �� ����� ����������� ProgressBar' �
Unload Me
End Sub
���, ��� ��������� � ���� ����� �����������, ����� �����������, � �� ����� ��� ����� ����� ���������� �� ������. �� ��������� ���������� ��������� ����� ����� ��������� (���� ��������� �� �� �����������, ���� ����� ��������� ��������� � ����������� �������������� ����������� ������ � ������). ������ ������� ������ ������� ������ �������������� � ��� ����� �� �����.
3.����� ������. ������ ������� ������� "Label3" ����� �������� ����������. ������� ��� ����������� ProgressBar'� ���� �������� � ��� ������, ���������� ������ ���� �������. � �������, ���� � ��������� ������������n ���. ����� ������ ������� "Label3" ����� ������������ �������� � ���� ����� �� ������� "Label3.Width = (scet/n)*250", ��� "scet" � ��� ������� �����, � 250 � ������ ������� Label2.
����� ������ ����� ������� ���� ��������� ���������� "Me.Repaint", ����� ������������ ����� � ������ ����� ���������� ������� �������,�� �������������� ����������� �� ������� ����������� ����� (������� ����������, ����� �������� ��������� ������� "UserForm_Activate()" � ����� �� ����� ���������) �� ����������. ���� ����� � ProgressBar'�� ������ ����� ��������� �� ������ ��� ���������, �� ������������� ������ ������������ ������� "Me.Repaint", ��� ��� ��� ����������� ������� ��� ����� ����� ���� ����� �������� ������ ������ ����������, ����� ������������ �����