总表的设置:说白了,总表就是数据库,所有基础数据都在这张表上,所有总表要严格按照数据库的制表方法来,拒绝重复,遗漏等记录 首先,ThisWorkbook代码如下:Private Sub workbook_open() Application.ScreenUpdating = False Me.Application.Visible = False 登陆.Show End Sub 这个代码会弹出一个登陆对话框并隐藏工作簿 存在问题,弹对话框前工作簿一闪一下的问题没有解决,而且现在也不会解决,让人很不爽
show窗体代码:Dim mm As BooleanPrivate Sub CommandButton1_Click() If TextBox1.Text = "0" Then mm = True 登陆.Hide UserForm2.Show Unload Me Else mm = False Unload Me MsgBox "你无权访问" ThisWorkbook.Application.Quit End If End Sub Private Sub userform1_activate() Application.ScreenUpdating = False TextBox1.SetFocus mm = False Application.ScreenUpdating = True End Sub Private Sub userform1_queryclose(Cancel As Integer, CloseMode As Integer) If Not mm Then ThisWorkbook.Application.Quit End Sub Private Sub CommandButton2_Click() ThisWorkbook.Application.Quit End Sub Private Sub Label3_Click()End SubPrivate Sub UserForm_Initialize() Application.ScreenUpdating = False With ComboBox1 .AddItem "此处省略工程名称或公司名字" End With ComboBox1.Text = "此处省略工程名称或公司名字" With ComboBox2 .AddItem "此处省略工程名称或公司名字" End With ComboBox2.Text = "此处省略工程名称或公司名字" With ComboBox3 .AddItem "此处省略工程名称或公司名字" End With ComboBox3.Text = "此处省略工程名称或公司名字" Application.ScreenUpdating = True End Sub 这个窗体基本功能可以,没有建立用户数据库,所以密码直接在代码硬设,这个不是问题,只需引入数据库就可以
Public i As Worksheet Public a, b, c, d, e, z1 As String Public j, k As Integer Dim arr(1 To 25) As Long 这是写在最顶端的共有变量。 实话实说,VB的共有变量,私有变量,全局变量我用的不好,主要研究的也少,所以这样设变量合适不合适,有待考究。
“显示”按钮事件 Private Sub CommandButton1_Click() Application.ScreenUpdating = False Call 赋值 Call 判断检验批 If j >= 2000 Then Exit Sub End If Call 需显工作表 UserForm2.Hide ThisWorkbook.Application.Calculate Application.ScreenUpdating = True End Sub 那个2000是2楼提出数据总表的记录总数
“直接打印”按钮事件Private Sub CommandButton4_Click() Application.ScreenUpdating = False Call 赋值 Call 判断检验批 If j >= 2000 Then Exit Sub End If Call 需显工作表 For Each i In Worksheets If i.Visible = True Then i.PrintOut End If Next ' ThisWorkbook.Application.Calculate ThisWorkbook.Application.Visible = False Application.ScreenUpdating = True End Sub
函数模块 Private Sub 赋值() Application.ScreenUpdating = False ThisWorkbook.Application.Visible = True For Each i In Worksheets i.Visible = True Next c = ComboBox2.Text + ComboBox5.Text + ComboBox3.Text e = ComboBox2.Text + ComboBox5.Text + ComboBox4.Text d = c + "-" + e + "(DN" + ComboBox8.Text + ")" If ComboBox3.Text <> ComboBox4.Text Then a = d + ComboBox1.Text Else a = c + "支管" + "(DN" + ComboBox8.Text + ")" + ComboBox1.Text End If End SubPrivate Sub 需显工作表() If ComboBox1.Text = "沟槽开挖" Then For Each i In Worksheets If i.Name = "皮" Or i.Name = "槽检" Or i.Name = "槽隐" Or i.Name = "高程" Then i.Visible = True Else i.Visible = xlSheetHidden End If Next ElseIf ComboBox1.Text = "管道基础" Then For Each i In Worksheets If i.Name = "皮" Or i.Name = "基检" Or i.Name = "基隐" Or i.Name = "高程" Then i.Visible = True Else i.Visible = xlSheetHidden End If Next ElseIf ComboBox1.Text = "管道安装" Then For Each i In Worksheets If i.Name = "皮" Or i.Name = "安检" Or i.Name = "安隐" Or i.Name = "高程" Then i.Visible = True Else i.Visible = xlSheetHidden End If Next ElseIf ComboBox1.Text = "管道接口" Then For Each i In Worksheets If i.Name = "皮" Or i.Name = "口检" Or i.Name = "口隐" Then i.Visible = True Else i.Visible = xlSheetHidden End If Next Else For Each i In Worksheets If i.Name = "皮" Or i.Name = "填检" Or i.Name = "填隐" Or i.Name = "高程" Then i.Visible = True Else i.Visible = xlSheetHidden End If Next ' Else ' For Each i In Worksheets ' If i.Name = "皮" Or i.Name = "井检" Or i.Name = "井隐" Then '' i.Visible = True ' Else ' i.Visible = xlSheetHidden ' End If ' Next End If End Sub Private Sub 判断检验批() Sheets("总表").Select Cells(2, 1).Select For j = 1 To 2000 Step 1 If Cells(j, 1) = a Then Call 主程序 Exit For End If Next If j >= 2000 Then For Each i In Worksheets If i.Name = "勿删" Then i.Visible = xlSheetVisible Else i.Visible = xlSheetHidden End If Next MsgBox "本工程没有划分这个检验批!请确认后重新输入" End If End Sub