写的第一个可运行代码,一半来自网络。哈哈

Dim xlApp As Excel.Application '定义EXCEL类
Dim xlBook As Excel.Workbook '定义工件簿类
Dim xlsheet As Excel.Worksheet '定义工作表类

Private Sub Command1_Click() '更新工时数据
Dim lcmm As String
If Dir("" & App.Path & "\excel.bz") = "" Then '判断EXCEL是否打开
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFolder "\\192.168.X.X\路径", "E:\路径", True
'源文件夹 目标文件夹
MsgBox "更新成功"
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Else
End
End If
Do
lcmm = InputBox("请输入查询密码", "查询密码", "")
Loop Until lcmm = "0123" Or lcmm = "1231" Or lcmm = "1232" Or lcmm = "1233" Or lcmm = "1234" Or lcmm = "1235" Or lcmm = ""
Select Case lcmm
Case "0123"
Command2.Enabled = True
Case "1231"
Command3.Enabled = True
Case "1232"
Command4.Enabled = True
Case "1233"
Command5.Enabled = True
Case "1234"
Command6.Enabled = True
Case "1235"
Command7.Enabled = True
End Select
End Sub

Private Sub Command2_Click() '运行工时汇总系统
If Dir("D:\temp\excel.bz") = "" Then '判断EXCEL是否打开
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = True '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open("E:\路径\文件名.xlsm") '打开EXCEL工作簿
Set xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表
'xlsheet.Activate '激活工作表
'xlsheet.Cells(1, 1) = "abc" '给单元格1行驶列赋值
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏
Else
MsgBox ("EXCEL已打开")
End If
End
End Sub

Private Sub Command3_Click()
If Dir("D:\temp\excel.bz") = "" Then '判断EXCEL是否打开
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = True '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open("E:\路径\文件名.xlsm") '打开EXCEL工作簿
Set xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表
'xlsheet.Activate '激活工作表
'xlsheet.Cells(1, 1) = "abc" '给单元格1行驶列赋值
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏
Else
MsgBox ("EXCEL已打开")
End If
End
End Sub

Private Sub Command4_Click()
If Dir("D:\temp\excel.bz") = "" Then '判断EXCEL是否打开
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = True '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open("E:\路径\文件名.xlsm") '打开EXCEL工作簿
Set xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表
'xlsheet.Activate '激活工作表
'xlsheet.Cells(1, 1) = "abc" '给单元格1行驶列赋值
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏
Else
MsgBox ("EXCEL已打开")
End If
End
End Sub

Private Sub Command5_Click()
If Dir("D:\temp\excel.bz") = "" Then '判断EXCEL是否打开
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = True '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open("E:\路径\文件名.xlsm") '打开EXCEL工作簿
Set xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表
'xlsheet.Activate '激活工作表
'xlsheet.Cells(1, 1) = "abc" '给单元格1行驶列赋值
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏
Else
MsgBox ("EXCEL已打开")
End If
End
End Sub


Private Sub Command6_Click()
If Dir("D:\temp\excel.bz") = "" Then '判断EXCEL是否打开
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = True '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open("E:\路径\文件名.xlsm") '打开EXCEL工作簿
Set xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表
'xlsheet.Activate '激活工作表
'xlsheet.Cells(1, 1) = "abc" '给单元格1行驶列赋值
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏
Else
MsgBox ("EXCEL已打开")
End If
End
End Sub


Private Sub Command7_Click()
If Dir("D:\temp\excel.bz") = "" Then '判断EXCEL是否打开
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = True '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open("E:\路径\文件名.xlsm") '打开EXCEL工作簿
Set xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表
'xlsheet.Activate '激活工作表
'xlsheet.Cells(1, 1) = "abc" '给单元格1行驶列赋值
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏
Else
MsgBox ("EXCEL已打开")
End If
End
End Sub

Private Sub Form_Load()
Label1.FontSize = 20
Label1.FontBold = True
Label1.FontItalic = True
End Sub

Private Sub Image1_Click()
MsgBox "本软件只适用XXX公司内部使用,最后更新时间2019年9月10日。"
End Sub

转载于:https://www.cnblogs.com/wenweiqun/p/11535723.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值