Visual_Basic 板


LINE

載點: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)







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:iOS站內搜尋

TOP