VBA-加载项工具开发

之前写了一个简单的加载项菜单博客,应用于实际工作中,写了一个工具用于分配任务。

'create menus when this workbook opened
Public Sub createMenus()
    deleteMenus
    Dim cbMyTool As CommandBar
    Dim cbbMyButton As CommandBarButton

    'Make the toolbar
    Set cbMyTool = CommandBars.Add

    'Add a button to the toolbar.
    Set cbbMyButton = cbMyTool.Controls.Add(msoControlButton)
    With cbbMyButton
        .Caption = "taskAdd"
        .Style = msoButtonIconAndCaption
        .OnAction = "onClickBtn"
        .FaceId = 222
        .TooltipText = "button.TooltipText"
    End With

'The toolbar gets a name and is put on the screen.
   With cbMyTool
     .Name = "NPA Tools"
     .Visible = True
  End With
  
BeforeExit:
    Set cbMyTool = Nothing
    Set cbbMyButton = Nothing

    Exit Sub
ErrorHandle:
    Debug.Print Err.Description & " CreateMenus"
    Resume BeforeExit
End Sub

'delete menus we created before this workbook close.
Public Sub deleteMenus()
    'Removes the toolbar "Shortcuts".
    'If it doesn't exist we get an error,
    'and that is why we use On Error Resume Next.
    On Error Resume Next
    CommandBars("NPA Tools").Delete
End Sub


Public Sub onClickBtn()
    Dim rowCells, rowCell As Variant
    rowCells = readExcelRowCellsByPath
        Dim i As Integer
    For i = 2 To UBound(rowCells)
    copy_rows
    Next i
    

    For i = 0 To UBound(rowCells)
    
    Dim columnValues As Variant
    columnValues = Split(rowCells(i), ",")
    Cells(3 + 4 * i, 2).Value = columnValues(1)
    Cells(3 + 4 * i, 3).Value = columnValues(2)
    Cells(3 + 4 * i, 4).Value = columnValues(3)
    'Debug.Print columnValues(2)
    Next i

End Sub

Sub copy_rows()
' copy_rows Macro
    Range("B7:G10").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("B11").Select
    Selection.Insert Shift:=xlDown
    Range("B15").Select
End Sub



Option Explicit
'read excel by file_path
Public Function readExcelRowCellsByPath() As Variant
    Dim dataExcel, Workbook, sheet, totalColumn, redminePath
    Dim totalRow

    Set dataExcel = CreateObject("Excel.Application")
    redminePath = getFilePathByPicker
    Set Workbook = dataExcel.Workbooks.Open(redminePath)
    Set sheet = Workbook.Worksheets(1)
    
    totalRow = sheet.UsedRange.Rows.Count
    totalColumn = sheet.UsedRange.Columns.Count
    
    Dim arr, columnIndexs, columnValues As Variant
    Dim rowCells() As String
    ReDim rowCells(0 To totalRow - 2)

    arr = columnNames("#,題名,ストーリーポイント")
    Dim i, j As Long
    If totalRow > 1 And totalColumn > 1 Then
        For i = 2 To totalRow
           Dim oneRow As String
           For j = 1 To totalColumn
                If Not IsError(Application.Match(sheet.Cells(1, j).Value, arr, 0)) Then
                    oneRow = oneRow + "," + sheet.Cells(i, j).Value
                End If
            Next j
            rowCells(i - 2) = oneRow
            oneRow = ""
        Next i
    End If
    readExcelRowCellsByPath = rowCells
    Workbook.Close
End Function

'#,題名,予定工数
Public Function columnNames(ByVal targetStr As String) As Variant
columnNames = Split(targetStr, ",")
End Function

Public Function getFilePathByPicker() As String
Dim FileDialogObject
Set FileDialogObject = Application.FileDialog(msoFileDialogFilePicker)
With FileDialogObject
    .Title = "task issue from redmine"
    .InitialFileName = "C:\Users\Administrator\Downloads\issues.xlsx"
    .AllowMultiSelect = True
End With
FileDialogObject.Show
If FileDialogObject.SelectedItems.Count > 0 Then
getFilePathByPicker = FileDialogObject.SelectedItems(1)
End If
End Function

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VBA 开发人员手册,作者:解祥成。 目 录 第 1 章、VBA入门.......................................... 3 1 、了解嵌入和全局VBA工程 2、用VBA管理器组织工程 3、处理宏 4、用VBA IDE编辑工程 5、更多的信息 6、回顾AutoCAD VBA 工程术语 7、回顾AutoCAD VBA 命令 第 2 章、理解ActiveX自动操作基础 1、理解AutoCAD对象模型 2、访问对象层次 3、通过集合对象操作 4、理解属性和方法 5、理解父对象 6、定位类型库 7、在数据库中返回第一个图元 8、在方法和属性中使用变体 9、使用其它程序语言 第三章 控制AutoCAD环境 1、打开、保存和关闭图形 2、设定AutoCAD参数 5、重置活动对象 6、设定和返回系统变量 7、精确制图 8、提示用户输入 9、访问AutoCAD命令行 第四章 创建和编辑AutoCAD图元 1、创建对象 2、编辑对象 3、使用图层、颜色和线型 4、添加文本到图形中 第五章 标注与公差 1、标注的概念 2、创建标注 3、编辑标注 4、利用标注样式 5、在模型空间和图纸空间中标注 6、创建引线及注解 7、创建形位公差 第六章 定义菜单和工具栏 1、理解MenuBar和MenuGroups集合 2、加载菜单组 3、改变菜单条 4、创建和编辑下拉菜单和快捷菜单 5、建立并编辑工具栏 7、对菜单工具增加状态栏帮助 8、在右键菜单中增加条目 第七章 使用事件 1、了解AutoCAD中的事件 2、编写事件处理器的方法 3、处理应用程序级事件 4、处理文档级事件 5、处理对象级事件 第八章 在三维空间下工作 1、指定三维坐标 2、定义用户坐标系统 3、坐标转换 4、建立三维对象 5、在三维中编辑 6、编辑三维实体 第九章 定义布局及打印 1、了解模型空间和图纸空间 2、了解视口 3、打印图纸 第十章-高级绘图与组织技术 1、使用光栅图像 2、使用块和属性

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值