但如果用 TEXT 函數,就可把日期變為文字:
例如A1是日期,則
="今天是"&TEXT(A1, "M/D")
可讓儲存格顯示為:今天是1/12
而不會是:今天是43477
其他可參考:
https://support.office.com/zh-tw/article/text-%E5%87%BD%E6%95%B8-20d5ac4d-7b94-49fd-bb38-93d29371225c

="今天是"&TEXT(A1, "M/D")
F1:: ;win+shift+w,將所選日期轉換添加星期,以當年計算 ex:11/23→11/23(五)
OldClip = %Clipboard% ;把目前的剪貼簿內容先存起來
sleep, 200
Send, ^c
sleep, 200
Loop, Parse, Clipboard, /,
{
if A_Index <= 1 ;第1個循環存入v_month
v_month = %A_LoopField%
if A_Index <= 2 ;第2個循環存入v_day
v_day = %A_LoopField%
}
if v_month < 10 ;小於10加0
v_month = 0%v_month%
if v_day < 10 ;小於10加0
v_day = 0%v_day%
if A_MM > 11 ;如果當前月份大於11(也就是12月)
{
if v_month < 6 ;如果要輸入的月份小於6(也就是1~5月)
{
v_year := A_YYYY+1
}
else ;如果要輸入的月份大於等於6(也就是6~12月)
{
v_year := A_YYYY
}
}
else ;當前月份小於等於11(也就是1~12月)
{
v_year := A_YYYY
}
FormatTime, TimeString,%v_year%%v_month%%v_day%, WDay
TimeString := TimeString-1
V_CWday := SubStr("日一二三四五六", TimeString+1, 1) ;從字串開始向右複製不超過長度1的子字符串至V_CWday
sleep, 200
Clipboard = %Clipboard%(%V_CWday%)
sleep, 200
Send, ^v
Clipboard = %OldClip% ;恢復先前剪貼簿內容
return
@echo off start "" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\9splay_startup.exe"
F12::
V_PluginName = 權限管理外掛
V_Version = v6.3
V_Game = AAA, BBB ;遊戲
V_Name = Aaron, Claire, Jacky ; 名字
V_Function = 功能1, 功能2 ; 功能名稱
V_StartTime = %A_Now% ;紀錄開始時間
CoordMode ,Pixel, Screen ;設置座標模式相對於桌面 (整個屏幕)
CoordMode ,Mouse, Screen ;設置滑鼠座標模式相對於桌面 (整個屏幕)
BlockInput ,Mouse
WinWait, 9sPlay - Google Chrome,
IfWinNotActive, 9sPlay - Google Chrome, , WinActivate, 9sPlay - Google Chrome,
WinWaitActive, 9sPlay - Google Chrome,
Loop, Parse, V_Game, `, ;用 "," 解析 V_Game 字串並計算切割後的字串數量
{
V_GameNum =%A_Index%
}
Loop, Parse, V_Name, `, ;用 "," 解析 V_Name 字串並計算切割後的字串數量
{
V_NameNum =%A_Index%
}
Loop, Parse, V_Function, `, ;用 "," 解析 V_Function 字串並計算切割後的字串數量
{
V_FunctionNum =%A_Index%
}
V_ActionNum := V_GameNum*(V_NameNum+V_FunctionNum) ;計算動作數量
Gui, Color, White ;GUI顏色設定為白色
Gui, Add, Text, W600, 新增項目:%V_Game%`r`n`r`n人員:%V_Name%`r`n`r`n功能:%V_Function%`r`n ;新增本次工作內容文字
Gui, Add, Progress, vV_MyProgress w600 ;新增進度條至變量 V_MyProgress (在字母 V 後指定一個變量名, 此變量將為全局變量)
Gui, Add, Text, vV_MyText W600 Right ;新增文字至變量 V_MyText (在字母 V 後指定一個變量名, 此變量將為全局變量)
Gui +Resize +MaxSize640x480 +AlwaysOnTop -SysMenu ;GUI設定尺寸、保持最上層、去掉系統選單
Gui, Show, X-900 Y300 NoActivate, %V_PluginName% %V_Version% ;NoActivate 讓當前活動窗口繼續保持活動狀態
Loop, Parse, V_Game, `, ;用 "," 解析 V_Game 字串並執行本次工作內容
{
V_CurrentTime = %A_Now% ;紀錄當前時間
EnvSub, V_CurrentTime, %V_StartTime%, S ;以秒計算總共花了多少時間,並更新至 V_CurrentTime
V_EstimateTime := (V_CurrentTime//(A_Index)-1)*V_GameNum ;預測時間公式:(當前時間 V_CurrentTime//第 A_Index 個項目-1)*V_GameNum. (//)表示為向下捨除
V_ProgressPercentage := (A_Index/V_GameNum)*100 ;進度百分比公式:(A_Index 當前進度數/V_GameNum 總遊戲數)*100
GuiControl,, V_MyProgress, %V_ProgressPercentage% ;更新進度條
if A_Index <= 1
{
GuiControl,, V_MyText, 目前執行到第%A_Index%/%V_GameNum%個項目"%A_LoopField%",已使用時間計算中,預期時間計算中 ;更新進度文字至變量 V_MyText
Gosub, L_AutoAction ;開權限主要動作
}
else
{
GuiControl,, V_MyText, 目前執行到第%A_Index%/%V_GameNum%個項目"%A_LoopField%",已使用%V_CurrentTime%秒,預期使用%V_EstimateTime%秒 ;更新進度文字
Gosub, L_AutoAction ;開權限主要動作
}
}
V_CurrentTime = %A_Now% ;紀錄結束時間
EnvSub, V_CurrentTime, %V_StartTime%, S ;計算總共花了多少時間
MsgBox, 262144, %V_PluginName% %V_Version%, 新增項目:%V_Game%`r`n`r`n人員:%V_Name%`r`n`r`n功能:%V_Function%`r`n`r`n太棒了!你又節省了%V_CurrentTime%秒!
Gui,Destroy
FileAppend, %A_YYYY%/%A_MM%/%A_DD% %A_Hour%:%A_Min%:%A_Sec%`, %V_Version% save action`,%V_ActionNum% `, and time(second)`, %V_CurrentTime%`n, %A_ScriptDir%\9SplayBackgroundPluginLog.txt ;輸出日誌
Run, %A_ScriptDir%\9SplayBackgroundPluginLog.txt ;開啟日誌
Return
L_SaveFind1: ;搜尋字串後尋找搜尋色塊
OldClip = %Clipboard% ;把目前的剪貼簿內容先存起來
Clipboard = %A_LoopField% ;將字串替換至剪貼簿
Sleep, 300
send, ^f ;搜尋字串
Sleep, 300
send, ^v ;貼上複製內容
Sleep, 700
PixelSearch, V_ColorCoordinateX, V_ColorCoordinateY, -746, -897, -36, 300, 0x3296FF, 3, Fast ;尋找搜尋色塊
Return
L_SaveFind2: ;點擊座標修正後的勾選框
Sleep, 300
mousemove, %V_NewColorCoordinateX%, %V_NewColorCoordinateY%
Mouseclick, Left, %V_NewColorCoordinateX%, %V_NewColorCoordinateY% ;點擊座標修正後的勾選框
Sleep, 300
Clipboard = %OldClip% ;恢復先前剪貼簿內容
Return
L_AutoAction: ;開權限主要動作
Mouseclick, Left, -924, -871, , 1 ;點項目選單
Sleep, 300
Send, %A_LoopField%{ENTER}
Sleep, 700
Loop ;判斷讀取條是否還在
{
PixelSearch, V_ColorCoordinateX, V_ColorCoordinateY, -999, 710, -989, 715, 0xFFFFFF, 3, Fast ;搜尋白色底色
if ErrorLevel ;如果讀取條還在
{
Sleep, 300
}
else
{
Loop, Parse, V_Name, `, ;用 "," 解析 V_Name 字串後搜尋,並點擊座標修正後的勾選框
{
Gosub L_SaveFind1
V_NewColorCoordinateX := V_ColorCoordinateX-62 ;名字座標修正
V_NewColorCoordinateY := V_ColorCoordinateY+5 ;名字座標修正
Gosub L_SaveFind2
}
Loop, Parse, V_Function, `, ;用 "," 解析 V_Function 字字串後搜尋,並點擊座標修正後的勾選框
{
Gosub L_SaveFind1
V_NewColorCoordinateX := V_ColorCoordinateX-42 ;功能座標修正
V_NewColorCoordinateY := V_ColorCoordinateY+5 ;功能座標修正
Gosub L_SaveFind2
}
PixelSearch, V_ColorCoordinateX, V_ColorCoordinateY, -746, -897, -36, 300, 0xDEC05B, 3, Fast ;搜尋確定更改
V_NewColorCoordinateX := V_ColorCoordinateX+25 ;確定更改座標修正
V_NewColorCoordinateY := V_ColorCoordinateY+10 ;確定更改座標修正
Sleep, 300
Mouseclick, Left, %V_NewColorCoordinateX%,%V_NewColorCoordinateY% ;點確定更改
Break
}
}
Loop ;判斷修正完成蓋台還沒出現
{
PixelSearch, V_ColorCoordinateX, V_ColorCoordinateY, -999, 710, -989, 715, 0x7F7F7F, 3, Fast ;搜尋灰色蓋台色
if ErrorLevel ;如果修正完成蓋台還沒出現
{
Sleep, 300
}
else
{
Mouseclick, Left, -924, -855, , 3 ;把蓋台按掉
Sleep, 1000
Break
}
}
Return
Private Sub CommandButton1_Click()
Sheets("TWN").Select
'宣告變數
Dim QuerySheet As Worksheet
Dim DataSheet As Worksheet
Dim qurl As String
Dim NOW, BN, LTH As Long
NOW = Sheets("TWN").Range("A4")
BN = Sheets("TWN").Range("A9")
LTH = Sheets("TWN").Range("A8")
'告訴Excel不要每更新一格就重新計算
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
'將現在的工作表設為資料表
Set DataSheet = ActiveSheet
qurl = "http://www.gretai.org.tw/storage/emgstk/ch/new.csv"
'選擇TWN sheet
Sheets("TWN").Range("B:Z").Clear
If NOW >= BN Then
If LTH < 16 Then
'如果時間是16:00之前
'抓取資料(TWN sheet)
QueryQuote:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("B1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
.RefreshStyle = xlInsertEntireRows
.Delete
End With
'讓Excel重新活回來,讓資料能夠顯示
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
'切數據(TWN sheet)
Sheets("TWN").Columns("B:B").Select
Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), _
TrailingMinusNumbers:=True
'否則(如果時間是16:00之後)
Else
'抓取資料(TWN sheet)
QueryQuote2:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("B1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
.RefreshStyle = xlInsertEntireRows
.Delete
End With
'讓Excel重新活回來,讓資料能夠顯示
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
'切數據(TWN sheet)
Sheets("TWN").Columns("B:B").Select
Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), _
TrailingMinusNumbers:=True
'更新上一交易日(TWN sheet的BN變數)
Sheets("TWN").Range("A4:A7").Select
Selection.Copy
Sheets("TWN").Range("A9").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'選擇TWO sheet
Sheets("TWO").Select
'告訴Excel不要每更新一格就重新計算
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
'將現在的工作表設為資料表
qurl = "http://www.tpex.org.tw/web/stock/aftertrading/otc_quotes_no1430/stk_wn1430_print.php?l=zh-tw&d=" + Sheets("TWO").Range("A9") + "/" + Sheets("TWO").Range("A10") + "/" + Sheets("TWO").Range("A11") + "&se=EW&s=0,asc,0"
Sheets("TWO").Range("B:Z").Clear
'抓取資料(TWO)
QueryQuote3:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=Sheets("TWO").Range("B1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
.RefreshStyle = xlInsertEntireRows
.Delete
End With
'讓Excel重新活回來,讓資料能夠顯示
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
'選擇TW sheet
Sheets("TW").Select
'將現在的工作表設為資料表
Set DataSheet = ActiveSheet
qurl = "http://www.tse.com.tw/exchangeReport/MI_INDEX?response=csv&date=" + Sheets("TW").Range("A9") + Sheets("TW").Range("A10") + Sheets("TW").Range("A11") + "&type=ALLBUT0999"
Sheets("TW").Range("B:Z").Clear
'抓取資料(TW sheet)
QueryQuote4:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("B1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
.RefreshStyle = xlInsertEntireRows
.Delete
End With
'讓Excel重新活回來,讓資料能夠顯示
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
'切數據(TW sheet)
Sheets("TW").Columns("B:B").Select
Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), _
TrailingMinusNumbers:=True
End If
End If
'選擇關注 sheet
Sheets("關注").Select
End Sub
Private Sub CommandButton1_Click()
'宣告變數
Dim QuerySheet As Worksheet
Dim DataSheet As Worksheet
Dim qurl As String
'告訴Excel不要每更新一格就重新計算
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
'將現在的工作表設為資料表
Set DataSheet = ActiveSheet
qurl = "http://www.tse.com.tw/exchangeReport/MI_INDEX?response=csv&date=" + Range("A9") + Range("A10") + Range("A11") + "&type=ALLBUT0999"
Range("B:Z").Clear
'抓取資料
QueryQuote:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("B1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
.RefreshStyle = xlInsertEntireRows
.Delete
End With
'讓Excel重新活回來,讓資料能夠顯示
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
'切數據
Columns("B:B").Select
Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), _
TrailingMinusNumbers:=True
End Sub
抓上櫃股票:
Private Sub CommandButton1_Click()
'宣告變數
Dim QuerySheet As Worksheet
Dim DataSheet As Worksheet
Dim qurl As String
'告訴Excel不要每更新一格就重新計算
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
'將現在的工作表設為資料表
Set DataSheet = ActiveSheet
qurl = "http://www.tpex.org.tw/web/stock/aftertrading/otc_quotes_no1430/stk_wn1430_print.php?l=zh-tw&d=" + Range("A9") + "/" + Range("A10") + "/" + Range("A11") + "&se=EW&s=0,asc,0"
Range("B:Z").Clear
'抓取資料
QueryQuote:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("B1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
.RefreshStyle = xlInsertEntireRows
.Delete
End With
'讓Excel重新活回來,讓資料能夠顯示
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
End Sub
抓興櫃股票:
Private Sub CommandButton1_Click()
'宣告變數
Dim QuerySheet As Worksheet
Dim DataSheet As Worksheet
Dim qurl As String
'告訴Excel不要每更新一格就重新計算
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
'將現在的工作表設為資料表
Set DataSheet = ActiveSheet
qurl = "http://www.gretai.org.tw/storage/emgstk/ch/new.csv"
Range("B:Z").Clear
'抓取資料
QueryQuote:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("B1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
.RefreshStyle = xlInsertEntireRows
.Delete
End With
'讓Excel重新活回來,讓資料能夠顯示
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
'切數據
Columns("B:B").Select
Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), _
TrailingMinusNumbers:=True
End Sub