喜歡攝影的我,喜歡到處拍拍照,吃點當地的特色食物。 跟朋友聊天之餘,推薦我寫成網誌跟大家分享。 沒外出的日子,喜歡在家當隱性宅,寫程式看看書,追劇。 希望我的手札文,不會讓你翻桌 XD
2021年1月31日 星期日
2021年1月30日 星期六
2021年1月24日 星期日
vba:換行跟常用的符號
整理給自己查,也作分享
2021年1月18日 星期一
VBA:用LINE NOTIIFY 作股價追踪
2021年1月13日 星期三
VBA:連結;Hyperlinks
最基本的參數參:Hyperlinks.Add、Hyperlinks 物件
小編最常用的是連結開啟檔案、連結MAIL、連結網站、連結工作表的儲存格
寫給自己看,也作分享
連結開啟檔案:
SOURCE_SHEET=ACTIVESHEET.NAME | |
Sheets(SOURCE_SHEET).Range("B" & i).Hyperlinks.Delete | |
Sheets(SOURCE_SHEET).Range("B" & i).Hyperlinks.Add Anchor:=Sheets(SOURCE_SHEET).Range("B" & i), Address:=FILE_PATH, _ | |
TextToDisplay:="'" & Sheets(SOURCE_SHEET).Range("B" & i).Value '"'"是避免數字錯誤。 |
連結網站:參考:Hyperlinks.Add
連結工作表的儲存格:
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
"'工作表名稱'!儲存格位置如A1", TextToDisplay:="鉀肥"
Sheets("工作表1").Range("a" & i).Hyperlinks.Delete | |
Sheets("工作表1").Range("a" & i).Hyperlinks.Add Anchor:=Sheets("工作表1").Range("a" & i), Address:="", SubAddress:=stock & "!A1", TextToDisplay:=Sheets("工作表1").Range("a" & i).Value '& "'" | |
stock:工作表名稱的變數
2021年1月12日 星期二
VBA:即時技術分析+即時股價 V2
2021年1月11日 星期一
VBA:新增與刪除定義名稱
想寫一個自動更新折線圖的資料,最簡單的方法就是加入"定義名稱",透過"定義名稱"來控制折線圖的資料區間。
主要要使用到WORKBOOKS的NAME屬性來新增。MSDN
主要語法:
ActiveWorkbook.Names.Add Name:=名稱, RefersTo:=參照儲存格位置
名稱可以自訂,參照儲存格位置這邊建議寫完整一點,才不會出包。
EX:
ActiveWorkbook.Names.Add Name:="TEST", RefersTo:="=" & "OSC" & "!$" & "A" & "$2:" & "$" & "A" & "$" & 10
新增一個名為TEST的定義名稱,參照 OSC工作表的A2:A10儲存格。
指定刪除:
ActiveWorkbook.Names(定義名稱).Delete
全部刪除:
Dim Name_UNIT As Name
For Each Name_UNIT In Application.ActiveWorkbook.Names
Name_UNIT .Delete
Next
2021年1月10日 星期日
VBA:水平置中、垂直置中與其他設定
寫給自己速查
垂直屬性:HorizontalAlignment
水平屬性:VerticalAlignment
置中:xlCenter
靠左靠右:XLLEFT、XLRIGHT
Sheets("工作表1").Range("m2").VerticalAlignment = xlCenter
Sheets("工作表1").Range("m2").HorizontalAlignment = xlCenter
Sheets("工作表1").Range("m2").VerticalAlignment = XLRIGHT
Sheets("工作表1").Range("m2").HorizontalAlignment = XLRIGHT
Sheets("工作表1").Range("m2").VerticalAlignment = XLLEFT
Sheets("工作表1").Range("m2").HorizontalAlignment = XLLEFT
VBA:即時技術分析+即時股價
2021年1月9日 星期六
VBA:一維陣列資料堆壘
Function ARRAY_Pile(INPUT_ARRAY, SYMBOL) | |
If IsArray(INPUT_ARRAY) = True Then | |
Dim ARRAY_STOCK_TOTAL As String | |
For i = LBound(INPUT_ARRAY) To UBound(INPUT_ARRAY) Step 1 | |
If i = LBound(INPUT_ARRAY) Then | |
ARRAY_STOCK_TOTAL = INPUT_ARRAY(i) | |
Else | |
If INPUT_ARRAY(i) <> "" Then | |
ARRAY_STOCK_TOTAL = ARRAY_STOCK_TOTAL & SYMBOL & INPUT_ARRAY(i) | |
End If | |
End If | |
Next i | |
ARRAY_Pile = ARRAY_STOCK_TOTAL | |
Else | |
ARRAY_Pile = INPUT_ARRAY '2020.12.24 ARRAY_STOCK = 0 | |
End If | |
End Function |
2021年1月8日 星期五
2021年1月3日 星期日
VBA 開啟檔案 (二) FileDialog應用:開盤、收盤價、最高、最低、成交量整理
Private Sub CommandButton1_Click() | |
Dim FILE_OPEN As FileDialog '宣告FILE_OPEN為檔案對話框 | |
Set FILE_OPEN = Excel.Application.FileDialog(msoFileDialogFilePicker) | |
'設定FILE_OPEN為選取檔案功能 | |
FILE_OPEN.InitialFileName = Excel.ActiveWorkbook.Path '對話框開始目錄的設定 | |
FILE_OPEN.Filters.Add "Excel File", "*.xls*" '設定對話框要顯示的副檔名 | |
FILE_OPEN.Filters.Add "所有檔案", "*.*" | |
FILE_OPEN.Show '顯示對話框 | |
For I = 1 To FILE_OPEN.SelectedItems.Count | |
Source = Excel.ActiveWorkbook.Name '儲存目前作業中檔案名稱 | |
FILE_OPEN_PATH = FILE_OPEN.SelectedItems(I) '取的檔案路徑 | |
Workbooks.Open Filename:=FILE_OPEN_PATH '開啟案路徑 | |
WORKNAME = Excel.ActiveWorkbook.Name '儲存新開檔案的檔案名稱 | |
'新增的部分 | |
S1 = ActiveSheet.Range("A2000").End(xlUp).Row | |
Data = ActiveSheet.Range("A2:H" & S1) | |
Windows(WORKNAME).Close '啟用新開檔案的檔案名稱 | |
Windows(Source).Activate '啟用目前作業中檔案名稱 | |
S2 = ActiveSheet.Range("A655360").End(xlUp).Row | |
If S2 = 1 Then | |
Sheets("工作表1").Range("A2:H" & S1) = Data | |
Else | |
Sheets("工作表1").Range("A" & S2 + 1 & ":G" & S1 + S2 - 1) = Data | |
End If | |
Next I | |
End Sub |
2021年1月2日 星期六
VBA:玩玩儲存格資料橫條顏色色階(AddDatabar)
老樣子來一下MSDN:FormatConditions.AddDataBar
Private Sub CommandButton1_Click() | |
sheet_name = ActiveSheet.Name | |
Set rg = Sheets(sheet_name).Range("A" & 2) | |
rg.FormatConditions.Delete | |
rg.FormatConditions.AddDatabar | |
End Sub |
Private Sub CommandButton1_Click() | |
sheet_name = ActiveSheet.Name | |
END_FOR = Sheets(sheet_name).Range("a5000").End(xlUp).Row | |
For I = 2 To END_FOR Step 1 | |
Set rg = Sheets(sheet_name).Range("A" & I & ":C" & I) | |
Min = Application.Min(rg) | |
Max = Application.Max(rg) | |
For Each rg1 In rg | |
If rg1.Value = 0 Then | |
rg1.FormatConditions.Delete | |
End If | |
If rg1.Value > 0 Then | |
rg1.FormatConditions.Delete | |
rg1.FormatConditions.AddDatabar | |
rg1.FormatConditions(rg1.FormatConditions.Count).ShowValue = True | |
rg1.FormatConditions(rg1.FormatConditions.Count).SetFirstPriority | |
With rg1.FormatConditions(1) | |
.MinPoint.Modify newtype:=xlConditionValueNumber, newValue:=0 'xlConditionValueAutomaticMin | |
.MaxPoint.Modify newtype:=xlConditionValueNumber, newValue:=Max * 1.5 | |
End With | |
With rg1.FormatConditions(1).BarColor | |
.Color = RGB(255, 77, 64) | |
.TintAndShade = 0 | |
End With | |
rg1.FormatConditions(1).BarFillType = xlDataBarFillGradient | |
rg1.FormatConditions(1).Direction = xlContext | |
rg1.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor | |
rg1.FormatConditions(1).BarBorder.Type = xlDataBarBorderSolid | |
rg1.FormatConditions(1).NegativeBarFormat.BorderColorType = _ | |
xlDataBarColor | |
With rg1.FormatConditions(1).BarBorder.Color | |
.Color = RGB(255, 77, 64) | |
.TintAndShade = 0 | |
End With | |
rg1.FormatConditions(1).AxisPosition = xlDataBarAxisAutomatic | |
With rg1.FormatConditions(1).AxisColor | |
.Color = 0 | |
.TintAndShade = 0 | |
End With | |
With rg1.FormatConditions(1).NegativeBarFormat.Color | |
.Color = 255 | |
.TintAndShade = 0 | |
End With | |
With rg1.FormatConditions(1).NegativeBarFormat.BorderColor | |
.Color = 255 | |
.TintAndShade = 0 | |
End With | |
If rg1.Value >= 3 Then | |
rg1.FormatConditions.Delete | |
rg1.FormatConditions.AddDatabar | |
rg1.FormatConditions(rg1.FormatConditions.Count).ShowValue = True | |
rg1.FormatConditions(rg1.FormatConditions.Count).SetFirstPriority | |
With rg1.FormatConditions(1) | |
.MinPoint.Modify newtype:=xlConditionValueNumber, newValue:=0 'xlConditionValueAutomaticMin | |
.MaxPoint.Modify newtype:=xlConditionValueNumber, newValue:=Max * 1.5 | |
End With | |
With rg1.FormatConditions(1).BarColor | |
.Color = RGB(255, 77, 64) | |
.TintAndShade = 0 | |
End With | |
rg1.FormatConditions(1).BarFillType = xlDataBarFillGradient | |
rg1.FormatConditions(1).Direction = xlContext | |
rg1.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor | |
rg1.FormatConditions(1).BarBorder.Type = xlDataBarBorderSolid | |
rg1.FormatConditions(1).NegativeBarFormat.BorderColorType = _ | |
xlDataBarColor | |
With rg1.FormatConditions(1).BarBorder.Color | |
.Color = RGB(255, 77, 64) | |
.TintAndShade = 0 | |
End With | |
rg1.FormatConditions(1).AxisPosition = xlDataBarAxisAutomatic | |
With rg1.FormatConditions(1).AxisColor | |
.Color = 0 | |
.TintAndShade = 0 | |
End With | |
With rg1.FormatConditions(1).NegativeBarFormat.Color | |
.Color = 255 | |
.TintAndShade = 0 | |
End With | |
With rg1.FormatConditions(1).NegativeBarFormat.BorderColor | |
.Color = 255 | |
.TintAndShade = 0 | |
End With | |
End If | |
End If | |
If rg1.Value < 0 Then | |
rg1.FormatConditions.Delete | |
rg1.FormatConditions.AddDatabar | |
rg1.FormatConditions(rg1.FormatConditions.Count).ShowValue = True | |
rg1.FormatConditions(rg1.FormatConditions.Count).SetFirstPriority | |
With rg1.FormatConditions(1) | |
.MinPoint.Modify newtype:=xlConditionValueNumber, newValue:=0 | |
.MaxPoint.Modify newtype:=xlConditionValueNumber, newValue:=Min * 1.5 | |
End With | |
With rg1.FormatConditions(1).BarColor | |
.Color = RGB(54, 191, 54) | |
.TintAndShade = 0 | |
End With | |
rg1.FormatConditions(1).BarFillType = xlDataBarFillGradient | |
rg1.FormatConditions(1).Direction = xlContext | |
rg1.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor | |
rg1.FormatConditions(1).BarBorder.Type = xlDataBarBorderSolid | |
rg1.FormatConditions(1).NegativeBarFormat.BorderColorType = _ | |
xlDataBarColor | |
With rg1.FormatConditions(1).BarBorder.Color | |
.Color = RGB(54, 191, 54) | |
.TintAndShade = 0 | |
End With | |
rg1.FormatConditions(1).AxisPosition = xlDataBarAxisAutomatic | |
With rg1.FormatConditions(1).AxisColor | |
.Color = 0 | |
.TintAndShade = 0 | |
End With | |
With rg1.FormatConditions(1).NegativeBarFormat.Color | |
.Color = RGB(54, 191, 54) | |
.TintAndShade = 0 | |
End With | |
With rg1.FormatConditions(1).NegativeBarFormat.BorderColor | |
.Color = RGB(54, 191, 54) | |
.TintAndShade = 0 | |
End With | |
End If | |
Next | |
Next I | |
End Sub |
指數變化(2025.03.20)
指數變化(2025.03.20) 上周焦點: 美國紐約州製造業指數 -20 美國企業庫存月增率 +0.3% 美國零售額月增率 +0.1% FED 不升息 川普 名句:對等關稅是具備彈性的 本周愛看: 美國消費者信心指數 3/25 美國耐久財訂單月增率 3/26 ...

-
寫給自己速查 垂直屬性:HorizontalAlignment 水平屬性:VerticalAlignment 置中:xlCenter 靠左靠右:XLLEFT、XLRIGHT Sheets("工作表1").Range("m2").Ve...
-
美國實質可支配所得 利率與黃金 消費者信心 利率PK DW PK FED紐約分行 上海貨櫃指數 BDI CRB 美國m 1 m2 s&p 美國 非農 美國 非農就業職務空缺率 美國股市 行事曆 fomc 會議紀要與開會時間 全球股市行事曆 全球股市 巴菲特指數 外...
-
整理資料時,不免要判斷資料數量,在判斷資料時,資料有時會有不連續與連續資料,這時候判斷方式不盡相同 連續資料時: a行於65000儲存格以前的最後列,有點饒舌;應該是這樣看,從a65000往上找(xlup),找到的第一個儲存格,也相對於是a行在65000列之前最後一列。 END...