VBA Add-Ins Question

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.
Why do you think the Workbook_Open isn't right? Here's a resource that indicates that IS where it should go: cpearson.com/excel/createaddin.aspx

以上就是VBA Add-Ins Question的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » excel

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏