作者yinjing (青)
站内Visual_Basic
标题[VBA ] 献丑,简陋的定便当 Excel VBA
时间Thu Dec 11 22:28:54 2008
载点:
http://yvesjing.miroko.tw/BadonVBA.xls
(听说这空间只能外连到年底,反正到年底这文章也沉了没差 XD)
说明:目前只有弄定便当并统计、随机建议要定啥便当、清除所有资料,还有一些防呆
(不过这篇主要功能只是给人参考些函式基本用法 囧)
虽然不怎麽好用,但是是为了拿来练习一下VB = =||
不过由於偷懒,便当厂商跟菜单写死的 XD
要新增可以,不过请自行放到 Sheet2 里面并在程式码里面修改 XD
要用巨集必须将 [工具] -> [巨集] -> [安全性] 改成中或以下 @@
由於没啥基础,只是拿来练习用,所以函式用的蛮乱的,结构不良之类的就别鞭我了 Orz
下面简单介绍怎麽进去Excel的VBA编辑画面骗点P币 ( ̄ε(# ̄) #○=(一-一o)
--
首先开启 Excel
[工具] -> [巨集] -> [Visual Basic 编辑器],[滑鼠左键]单击
在跳出Visual Basic 编辑器视窗中 [插入] -> [自订表单],[滑鼠左键]单击
然後就跟VB的介面差不多了 ( ̄▽ ̄#)﹏﹏
如果想要Excel开启时就启动先前设计的VBA
在Visual Basic 编辑器视窗中左上的[专案]视窗的[ThisWorkBook]上[滑鼠左键]点两下
然後在[Book1 - ThisWorkBook (程式码)]视窗里贴上以下内容
Private Sub Workbook_Open()
UserForm1.Show
End Sub
[自订表单] 一开始预设名称应该是 [UserForm1],不是的话再自己改罗
--
不过第一次使用这东西当就出现很多问题了
一个是下拉式不方便看,也许以後改列表比较好
然後打电话时发现有些卖完了 =口=
要联络哪些人改餐很不方便,更OX的是有些还有涨价 Orz
总之一整个手忙脚乱 ˋ(′_‵||)ˊ
等哪天想不开再来改吧......
对了,如果有人想拿去修改玩玩
甚至交作业 的请自取,不用先徵得我同意
不要拿去卖
这种也卖不出去吧 XD 或宣称原着就好了
(老师问例外 囧
附注:
本着作依据 Creative Commons 姓名标示-非商业性-相同方式分享 授权条款为授权
http://creativecommons.org/licenses/by-nc-sa/2.0/tw/
--
'补一下程式码
Dim number As Integer
Dim total As Integer
Private Sub UserForm_Activate() '先载入点餐者名单与店家名称等
number = 2
While Cells(number, 1) <> "" And Cells(number, 1) <> "共计"
number = number + 1
Wend
total = 2
While Cells(total, 6) <> ""
total = total + 1
Wend
Label2.Caption = "今天: " & Date & " 星期" & Weekday(Date)
ComboBox1.AddItem "老师"
For i = 2 To 31
ComboBox1.AddItem i - 1
Next
ComboBox1.AddItem "其他"
For i = 1 To 9
ComboBox2.AddItem Sheet2.Cells(1, i)
i = i + 1
Next
ComboBox3.Clear
End Sub
Private Sub ComboBox1_Change() '选学号後才可以点餐
If ComboBox2.Text <> "今天挑哪家呢" Then
ComboBox3.Locked = False
ComboBox3.Text = "菜单"
End If
If ComboBox3.Text = "菜单" Then
CommandButton1.Caption = "等候点餐"
CommandButton1.Enabled = False
CommandButton1.Locked = True
End If
End Sub
Private Sub ComboBox2_Change() '选店家名称後载入菜单
ComboBox3.Clear
If ComboBox2.Text = "宽中港" Then
For i = 2 To 18
ComboBox3.AddItem Sheet2.Cells(i, 1) & Sheet2.Cells(i, 2)
Next
ElseIf ComboBox2.Text = "佳佳" Then
For i = 2 To 15
ComboBox3.AddItem Sheet2.Cells(i, 3) & Sheet2.Cells(i, 4)
Next
ElseIf ComboBox2.Text = "KISS快餐" Then
For i = 2 To 25
ComboBox3.AddItem Sheet2.Cells(i, 5) & Sheet2.Cells(i, 6)
Next
ElseIf ComboBox2.Text = "向阳楼面食馆" Then
For i = 2 To 30
ComboBox3.AddItem Sheet2.Cells(i, 7) & Sheet2.Cells(i, 8)
Next
ElseIf ComboBox2.Text = "鑫鲜园铁板烧烤" Then
For i = 2 To 32
ComboBox3.AddItem Sheet2.Cells(i, 9) & Sheet2.Cells(i, 10)
Next
End If
ComboBox2.Locked = True
If ComboBox1.Text = "号码?" Then
ComboBox3.Text = "请选择号码"
Else
ComboBox3.Locked = False
ComboBox3.Text = "菜单"
End If
CommandButton2.Locked = False
End Sub
Private Sub ComboBox3_Change() '点过餐才可以新增
If ComboBox3.Text <> "请选择号码" And ComboBox3.Text <> "菜单" Then
CommandButton1.Locked = False
CommandButton1.Enabled = True
CommandButton1.Caption = "确定新增"
End If
End Sub
Private Sub CommandButton1_Click() '将资料输入表格并统计
Sheet1.Cells(number, 1) = ComboBox1.Text
Sheet1.Cells(number, 2) = Left(ComboBox3.Text, Len(ComboBox3.Text) - 2)
Sheet1.Cells(number, 3) = TextBox1.Text
Sheet1.Cells(number, 4) = Right(ComboBox3.Text, 2) * TextBox1.Text
number = number + 1
Sheet1.Cells(number, 1) = "共计"
Sheet1.Cells(number, 2) = ComboBox2.Text
Sheet1.Cells(number, 3) = "=SUM(C2:C" & number - 1 & ")"
Sheet1.Cells(number, 4) = "=SUM(D2:D" & number - 1 & ")"
For i = 1 To total - 1
If Sheet1.Cells(i, 6) = Left(ComboBox3.Text, Len(ComboBox3.Text) - 2)
Then
Sheet1.Cells(i, 7) = Sheet1.Cells(i, 7) + TextBox1.Text
Sheet1.Cells(total, 6).Clear
Sheet1.Cells(total, 7).Clear
GoTo OK
Else
Sheet1.Cells(total, 6) = Left(ComboBox3.Text, Len(ComboBox3.Text)
- 2)
Sheet1.Cells(total, 7) = TextBox1.Text
End If
Next
total = total + 1
OK:
End Sub
Private Sub CommandButton2_Click()
MsgBox (ComboBox3.List(Rnd * 100 Mod ComboBox3.ListCount))
End Sub
Private Sub CommandButton3_Click() '清空重新点菜用的
Sheet1.Range("A2:G32").Clear
number = 2
total = 2
ComboBox1.Text = "号码?"
ComboBox2.Locked = False
ComboBox2.Text = "今天挑哪家呢"
ComboBox3.Text = "--"
ComboBox3.Locked = True
CommandButton1.Caption = "等候点餐"
CommandButton1.Enabled = False
CommandButton1.Locked = True
CommandButton2.Locked = True
End Sub
--
︴ 尼普蓝得的守护灵 托那鲁啊. ﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎
︴ 这里有一位获得你完整加护的勇士. ﹎﹎﹎﹎﹎﹎﹎
︴ 请你回顾记忆亚妮莉夏 美菈蓓死亡并立下誓约的瞬间, ﹎﹎﹎﹎﹎﹎﹎
︴ 这里有证明你们存在的言语, ﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎
︴ 欧半婆罗 罗贝 易险 莱贝雅 ﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎﹎ ╔╕ ┌╥
︴ 现在开启道路吧... ╘╝ └╯
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.126.52.79
※ yinjing:转录至看板 EZsoft 12/11 22:29
※ 编辑: yinjing 来自: 59.126.52.79 (12/11 22:32)