Created
June 19, 2023 11:48
-
-
Save tdalon/0ecac26a1d851218c3b8ddab2cef9d2b to your computer and use it in GitHub Desktop.
VBA Macros to Add multiple Links to Jira Issues via R4J Excel Add-In
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ILV_AddLinks() | |
' This function will add Link(s) to column named "New Issue Links" column | |
' It runs only for visible / unfiltered rows | |
' User will ask to input link:issuekey to add | |
' User can enter multiple links, comma separated | |
Dim sheet As Worksheet | |
Set sheet = ActiveSheet | |
' colLinks | |
Set cl = sheet.Rows(1).Find("New Issue Links") | |
If cl Is Nothing Then | |
' Duplicate Issue Links | |
Call ILV_DuplicateColumn | |
End If | |
Set cl = sheet.Rows(1).Find("New Issue Links") | |
If cl Is Nothing Then | |
MsgBox "New Issue Links column not found!", vbOKOnly, "Error" | |
Exit Sub | |
End If | |
colLinks = cl.Column | |
' Link Input | |
sLinks = InputBox("Please enter 'link:issuekey' to add (csv)") | |
If Len(sLinks) = 0 Then ' User cancelled | |
Exit Sub | |
End If | |
' Loop for all Rows in UsedRange - visible/ unfiltered only | |
For Each Row In sheet.UsedRange.SpecialCells(xlCellTypeVisible).Rows | |
' Skip header first row | |
If (cnt = 0) Then | |
GoTo SkipRow | |
End If | |
NewIssueLinksValue = Row.Cells(1, colLinks).Value | |
IsModified = False | |
For Each sLink In Split(sLinks, ",") | |
'Add a reference to Microsoft VBScript Regular Expressions 5.5 | |
' Remove white spaces after : | |
With New RegExp | |
.Pattern = ":\s*" | |
.MultiLine = True | |
.Global = True | |
sLink = .Replace(sLink, ":") | |
End With | |
' Remove redundant spaces | |
With New RegExp | |
.Pattern = "\s{2,}" | |
.MultiLine = True | |
.Global = True | |
sLink = .Replace(sLink, " ") | |
End With | |
If Not (ILV_IsLink(NewIssueLinksValue, sLink)) Then | |
IsModified = True | |
NewIssueLinksValue = NewIssueLinksValue & vbLf & Trim(sLink) | |
End If | |
Next sLink | |
ContinueRow: | |
' Update New Issue Links column with new value | |
If IsModified Then | |
Row.Cells(1, colLinks).Value = NewIssueLinksValue | |
End If | |
SkipRow: | |
cnt = cnt + 1 | |
Next Row | |
End Sub | |
Sub ILV_DuplicateColumn() | |
Dim sheet As Worksheet | |
Set sheet = ActiveSheet | |
' Duplicate Issue Links column to 'New Issue Links' Column | |
Set cl = sheet.Rows(1).Find("Issue Links") | |
If cl Is Nothing Then | |
MsgBox "Issue Links column not found!", vbOKOnly, "Error" | |
Exit Sub | |
End If | |
colLinks = cl.Column | |
Columns(colLinks + 1).Insert | |
cnt = 0 | |
For Each Row In sheet.UsedRange.Rows | |
' Skip header first row | |
If (cnt = 0) Then | |
Row.Cells(1, colLinks + 1).Value = "New Issue Links" | |
Else | |
Row.Cells(1, colLinks + 1).Value = Row.Cells(1, colLinks).Value | |
End If | |
cnt = cnt + 1 | |
Next Row | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See detailed explanation how to use https://tdalon.blogspot.com/2023/06/jira-add-multiple-links-r4j-xl-vba.html