I want to run my code when add-in loads. (Open excel file -> load addin -> run code)
But I have a problem with event handler.
I don't know what kind of event handler I need use and how to load installed addin.
(I try to use Workbook_open handler but I think it's wrong)
And I try to use Workbook_AddinInstall() event handler then when the install add-in, it works. But to make work my code, I need to reinstall add-in every time.
And How can I run add-in which already in the add-ins list.
Here is my code,
Private Sub Workbook_AddinInstall()
Dim counter As Long
Dim rowSize As Long
Dim userId As String
Dim answers As String
Dim vals As String
Dim i As Integer
Set currentSheet = ActiveWorkbook.ActiveSheet
MsgBox (currentSheet.Cells(1, 2).Value)
rowSize = currentSheet.Rows.Count
counter = 1
'Create Column
currentSheet.Cells(1, 7).Value = "Country"
currentSheet.Cells(1, 8).Value = "State"
currentSheet.Cells(1, 9).Value = "Age"
currentSheet.Cells(1, 7).Font.Bold = True
currentSheet.Cells(1, 8).Font.Bold = True
currentSheet.Cells(1, 9).Font.Bold = True
currentSheet.Cells(1, 7).HorizontalAlignment = xlCenter
currentSheet.Cells(1, 8).HorizontalAlignment = xlCenter
currentSheet.Cells(1, 9).HorizontalAlignment = xlCenter
currentSheet.Cells(1, 7).Borders().LineStyle = xlContinuous
currentSheet.Cells(1, 8).Borders().LineStyle = xlContinuous
currentSheet.Cells(1, 9).Borders().LineStyle = xlContinuous
'Set Value
Do While counter < rowSize
If currentSheet.Cells(counter, 1).Value = Null Then Exit Do
If currentSheet.Cells(counter, 4).Value = "3" Then
userId = currentSheet.Cells(counter, 2).Value
vals = currentSheet.Cells(counter, 6).Value
'MsgBox (vals)
temp = Split(vals, ",")
i = 0
Do While i < 10
targetCell = counter + i
If currentSheet.Cells(targetCell, 2).Value = userId Then
currentSheet.Cells(targetCell, 7).Value = temp(0)
currentSheet.Cells(targetCell, 8).Value = temp(1)
currentSheet.Cells(targetCell, 9).Value = temp(2)
currentSheet.Cells(targetCell, 7).HorizontalAlignment = xlCenter
currentSheet.Cells(targetCell, 8).HorizontalAlignment = xlCenter
currentSheet.Cells(targetCell, 9).HorizontalAlignment = xlCenter
currentSheet.Cells(targetCell, 7).Borders().LineStyle = xlContinuous
currentSheet.Cells(targetCell, 8).Borders().LineStyle = xlContinuous
currentSheet.Cells(targetCell, 9).Borders().LineStyle = xlContinuous
End If
i = i + 1
Loop
temp = Null
'parsing_question_1(vals, userId)
End If
counter = counter + 1
Loop
End Sub
Thank you.