'Filter fields in Tableau and download filtered files with VBA code
I want to write a code in Vba that when I click a button in Excel data, then in Tableau the fields are filled according to my Excel data and then the final filtered file is downloaded from Tableau. I have written this code but I get an empty Excel:
Sub GetSizeDataFromTableau(Optional strType As String = "")
Dim strLink As String
Dim wshshell As Object
With ThisWorkbook.Worksheets("Ordersheet")
If .Cells(1, 4) <> "" And .Cells(2, 4) <> "" And .Cells(2, 3) <> "" And .Cells(4, 43) <> "" Then 'Master Brand / Saison / Categorie 1 / Typ Produkttyp oder Categorie 2
strLink = "http://mymind.mytoys.group/#/views/ArticleSizeDistribution/Articlesizedistribution2" & strType & "?" & _
"&Switch off Target Grp/Gender on/off=on" & _
"&Purchase Department=PMM" & _
"&End Order Date (Transaction)=" & Year(Date) & "-" & Month(Date) & "-" & Day(Date) & _
"&order quantity=100" & _
"&Parameter.Category 1=" & .Cells(2, 3) & _
"&Parameter.Master Brand=" & .Cells(1, 4)
'Size data level
If UCase(.Cells(4, 43)) = "PT" Then
strLink = strLink & "&Switch between Dimensions=Product Type"
Else
strLink = strLink & "&Switch between Dimensions=Category 2"
End If
'Start Order Date
If Left(.Cells(2, 4), 2) = "FS" Then
strLink = strLink & "&Start Order Date (Transaction)=" & "20" & Right(.Cells(2, 4), 2) - 1 & "-01-01"
Else
strLink = strLink & "&Start Order Date (Transaction)=" & "20" & Right(.Cells(2, 4), 2) - 1 & "-07-01"
End If
'Supplier
If .Cells(1, 3) <> "" Then
strLink = strLink & "&Parameter.Primary Supplier=" & .Cells(1, 3)
End If
strLink = Replace(strLink, " ", "%20")
Set wshshell = CreateObject("WScript.Shell")
wshshell.Run strLink
If strType <> "" Then
.OLEObjects("cmdGetSizeData").Object.BackColor = RGB(0, 255, 0)
End If
Else
MsgBox "the following fields must be specified so that the size distribution data can be pulled from Tableau:" & vbNewLine & _
" - Size data level" & vbNewLine & _
" - Saison" & vbNewLine & _
" - Category 1" & vbNewLine & _
" - Marke" & vbNewLine & _
" Optional: Supplier"
End If
End With
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
