|
![](https://clubstatic.excelhome.net/image/common/ico_lz.png)
楼主 |
发表于 2016-5-1 21:48
|
显示全部楼层
本帖最后由 djk1020 于 2016-5-2 09:06 编辑
4、主界面菜单控件代码(三)
Private Sub CreateReport_Click(Index As Integer)
'生成报表:对当前窗口中汇总好了的数据 自动编号,再生成 号码对照表报表 和 比赛项目名单报表
With Xlapp
If .Workbooks.Count = 0 Then
MsgBox "文件被关闭!", vbInformation, MsgBoxTitle
ResetForm
Else
Me.PrintReport(123).Enabled = True '更改菜单状态
'自动生成报表
.ScreenUpdating = False '关闭屏幕更新
With .ActiveWorkbook
.Unprotect
MyApp.Report
.Protect Structure:=True, Windows:=True
End With
.Worksheets("号码对照表报表").Select
.Range("A1").Select
.ScreenUpdating = True '恢复屏幕更新
End If
End With
End Sub
Private Sub PrintReport_Click(Index As Integer)
'打印当前窗口中的报表(号码对照表和分组分道编排表)
If Xlapp.Workbooks.Count = 0 Then
MsgBox "文件被关闭!", vbInformation, MsgBoxTitle
ResetForm
Else
If MsgBox("准备好了要打印吗?", vbYesNo + vbQuestion, MsgBoxTitle) = vbYes Then
On Error Resume Next
Xlapp.Sheets(Array("号码对照表报表", "比赛项目名单报表")).PrintOut Copies:=1
End If
End If
End Sub
Private Sub Save_Click(Index As Integer)
If Xlapp.Workbooks.Count = 0 Then
MsgBox "文件被关闭!", vbInformation, MsgBoxTitle
ResetForm
Else
If Xlapp.ActiveWorkbook.Path <> "" Then
'存过盘的文件
Xlapp.ActiveWorkbook.Save
Else '未存过盘的新文件(基于模板新建的,应保存为.xls类型)
'从注册表读取默认目录
DefaultPath = GetSetting(ExcelName, "SportsMeetReportForms\MySection", "DefaultPath")
If DefaultPath = "" Then
'设置默认目录
MsgBox "请指定保存的默认目录!", vbInformation, MsgBoxTitle
DefaultPath = MyApp.PathLocation
If DefaultPath <> "1" Then
SaveSetting ExcelName, "SportsMeetReportForms\MySection", "DefaultPath", DefaultPath
Else
Exit Sub
End If
End If
'自动命名并保存到默认目录
File_Name = "号码对照表及分组分道编排表_" & Year(Date) & "-" & Right("0" & Month(Date), 2) & _
"-" & Right("0" & Day(Date), 2) & "_" & Right("00000" & Int(Timer), 5) & ".xls"
Xlapp.ActiveWorkbook.SaveAs DefaultPath + "\" + File_Name
End If
End If
End Sub
Private Sub Close_Click(Index As Integer)
'直接关闭Excel文件窗口(不保存更改)
With Xlapp
If .Workbooks.Count = 0 Then
MsgBox "文件被关闭!", vbInformation, MsgBoxTitle
Else
.ActiveWorkbook.Saved = True
.ActiveWorkbook.Close
.Visible = False
End If
End With
ResetForm
End Sub
Private Sub Quit_Click(Index As Integer)
'退出Excel和本系统
With Xlapp
If .Workbooks.Count <> 0 Then
.ActiveWorkbook.Saved = True
.ActiveWorkbook.Close
End If
.Quit '退出excel
End With
Unload Me '关闭程序主界面,退出本系统
End Sub
Private Sub DefaultFolder_Click(Index As Integer)
'设置默认目录
Dim bHide As Boolean
bHide = Xlapp.Visible
DefaultPath = GetSetting(ExcelName, "SportsMeetReportForms\MySection", "DefaultPath")
If DefaultPath <> "" Then
If MsgBox("默认目录已设置:" & Chr(10) & DefaultPath & Chr(10) & "要修改吗?", _
vbYesNo + vbQuestion, MsgBoxTitle) = vbYes Then
DefaultPath = MyApp.PathLocation
If bHide = False Then
Xlapp.Visible = False
End If
If DefaultPath = "1" Then
Exit Sub
End If
SaveSetting ExcelName, "SportsMeetReportForms\MySection", "DefaultPath", DefaultPath
End If
Else
MsgBox "请指定保存的默认目录!", vbInformation, MsgBoxTitle
DefaultPath = MyApp.PathLocation
If bHide = False Then
Xlapp.Visible = False
End If
If DefaultPath = "1" Then
Exit Sub
End If
SaveSetting ExcelName, "SportsMeetReportForms\MySection", "DefaultPath", DefaultPath
End If
End Sub
Private Sub initialize_Click(Index As Integer)
'打开模板,设置原始数据
With Xlapp
.Workbooks.Open FileName:=App.Path + "\号码对照表及分组分道编排.xlt", Editable:=True
.ActiveWorkbook.Unprotect
.ActiveWorkbook.Protect Structure:=True, Windows:=True
.Visible = True
End With
'更改菜单状态
With Me
.New(111).Enabled = False
.Open(112).Enabled = False
.initialize(22).Enabled = False
.Save(14).Enabled = True
.Close(15).Enabled = True
End With
End Sub
Private Sub About_Click(Index As Integer)
'打开关于界面
MyApp.About (RegTestBackVal)
End Sub
|
|