-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_KLPVENT.vb
166 lines (141 loc) · 5.1 KB
/
2_KLPVENT.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
'msoFileDialogFilePicker 允许用户选择一个文件
'msoFileDialogFolderPicker 允许用户选择一个文件夹
'msoFileDialogOpen 允许用户打开一个文件,选取多个文件
'msoFileDialogSaveAs 允许用户保存一个文件
Public fn As Integer '文件个数
Public rg As Range, c As Range '定位
Public ifcheck As Boolean '是否是对比计算
Private Sub Calcu_run_Click()
Dim i As Integer '循环用
Dim fadd As Integer '程序正式运行之前统计的已有文件数
Set rg = Sheets("KLPVENT").UsedRange
Set c = rg.Find("路径", lookat:=xlWhole)
fadd = 0
ifcheck = False
If Not c Is Nothing Then
For i = 1 To 3
If c.Offset(i, 0) <> "" Then
fadd = fadd + 1
End If
Next i
End If
If fadd > 0 Then
msg = MsgBox("好像已经选择了测量文件了,是否直接开始计算?", vbYesNoCancel)
If msg = vbCancel Then
End
End If
If msg = vbYes Then
fn = fadd
Call Calculate_pssp
End If
If msg = vbNo Then
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = True
.Filters.Clear
.Title = "选择测量文件"
.Filters.Add "测量文件", "*.dat"
.InitialFileName = ActiveWorkbook.Path
End With
If fd.Show = -1 Then
fn = fd.SelectedItems.Count
End If
If fn = 0 Then
MsgBox ("请至少选择一个测量文件!")
End
Else
If Not c Is Nothing Then
For i = 0 To fn - 1
c.Offset(i + 1, 0) = ""
c.Offset(i + 1, 0) = fd.SelectedItems(i + 1)
Next
MsgBox ("文件载入完成,如果选择了多个文件,程序只载入前三个。")
Else
MsgBox ("找不到单元格“路径”!请在“D2”单元格内写入“路径”然后重新运行程序。")
End
End If
Call Calculate_pssp
End If
End If
Else
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = True
.Filters.Clear
.Title = "选择测量文件"
.Filters.Add "测量文件", "*.dat"
.InitialFileName = ActiveWorkbook.Path
End With
If fd.Show = -1 Then
fn = fd.SelectedItems.Count
End If
If fn = 0 Then
MsgBox ("请至少选择一个测量文件!")
End
Else
If Not c Is Nothing Then
For i = 0 To fn - 1
c.Offset(i + 1, 0) = ""
c.Offset(i + 1, 0) = fd.SelectedItems(i + 1)
Next
MsgBox ("文件载入完成,如果选择了多个文件,程序只载入前三个。")
Else
MsgBox ("找不到单元格“路径”!请在“D2”单元格内写入“路径”然后重新运行程序。")
End
End If
Call Calculate_pssp
End If
End If
End Sub
Private Sub Check_KLPVENT_Click()
'
Dim i As Integer '循环用
Dim fadd As Integer '程序正式运行之前统计的已有文件数
Set rg = Sheets("KLPVENT").UsedRange
Set c = rg.Find("路径", lookat:=xlWhole)
fadd = 0
ifcheck = True
If Not c Is Nothing Then
For i = 1 To 3 '清空已选文件
c.Offset(i, 0) = ""
Next i
End If
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.Filters.Clear
.Title = "选择测量文件"
.Filters.Add "测量文件", "*.dat"
.InitialFileName = ActiveWorkbook.Path
End With
If fd.Show = -1 Then
fn = fd.SelectedItems.Count
End If
If fn = 0 Then
MsgBox ("请选择一个测量文件!")
End
Else
If Not c Is Nothing Then
c.Offset(1, 0) = ""
c.Offset(1, 0) = fd.SelectedItems(1)
Else
MsgBox ("找不到单元格“路径”!请在“D2”单元格内写入“路径”然后重新运行程序。")
End
End If
Call Calculate_pssp
End If
End Sub
Private Sub Load_clr_Click()
'清空KLPVENT中的文件列表
Set rg = Sheets("KLPVENT").UsedRange
Set c = rg.Find("路径", lookat:=xlWhole)
If Not c Is Nothing Then
For i = 0 To 2
c.Offset(i + 1, 0) = ""
Next i
End If
End Sub
Private Sub Readme_KLPVENT_Click()
'说明窗口
hlp.Show
End Sub