Code working in English Excel Not in Spanish Excel - Run Time Error 5 Argument Not Valid

mrmmickle1

Well-known Member
Joined
May 11, 2012
Messages
2,461
I have to get on a call later this afternoon regarding an error that is being produced in a Spanish Version of Excel (Argentina). I am trying to identify why my code is not working beforehand so that I can troubleshoot the issue on the fly. Does anyone have any idea why my code to create slicers would be breaking? I have identified that the break occurs someplace in this region of code. Does anyone see anything that stands out?

I have a feeling the Custom Slicers Style is not being converted from the English Version to Spanish Version.... (Can someone confirm this to be a known Issue?)

Code:
  [COLOR=#0000ff]   With[/COLOR] ActiveWorkbook.SlicerCaches
[COLOR=#008000]                  'Add the slicer[/COLOR]
                  .Add(pt, strSlicerName).Slicers.Add ActiveSheet, _
                      , strSlicerName, strSlicerName, 46, intSlicerPos, 160, 136

[COLOR=#008000]
'Code Breaks in this area someplace
'''==================================================================[/COLOR]
                      
                      ActiveSheet.Shapes(strSlicerName).Placement = xlFreeFloating[COLOR=#008000] 'Anchor Slicer[/COLOR]
                      
[COLOR=#008000]                      'Add to Filter In order to make the drill throughs work correctly in the Pivot Table[/COLOR]
                 [COLOR=#0000ff]     With[/COLOR] ActiveSheet.PivotTables("PivotTable1").PivotFields(strSlicerName)
                          .Orientation = xlPageField
                          .Position = 1
[COLOR=#0000ff]                      End With[/COLOR]
                
                   [COLOR=#0000ff]   With[/COLOR] ActiveWorkbook.SlicerCaches("Slicer_" & Replace(strSlicerName, " ", "_"))[COLOR=#008000] 'Replaces spaces with underscores[/COLOR]
                      
                          .Slicers(strSlicerName).SlicerCache.CrossFilterType = xlSlicerNoCrossFilter  [COLOR=#008000]'Allows items with no data not to appear in slicer[/COLOR]
                          .Slicers(strSlicerName).SlicerCache.ShowAllItems = False [COLOR=#008000] 'Removes Any Deleted Items[/COLOR]
[COLOR=#0000ff]                          .Slicers(strSlicerName).Style = "MySlicerStyle 2" 'Style of Slicer[/COLOR][COLOR=#ff0000] <------ My gut says it's this line
[/COLOR][COLOR=#008000]
'''==================================================================[/COLOR]
My goal is to identify the issue and then create a block of code similar to this:

Code:
 [COLOR=#0000ff]Select Case[/COLOR] Application.International(xlCountryCode)
    [COLOR=#0000ff]Case[/COLOR] 31: MsgBox "Run code for Dutch"
 [COLOR=#0000ff]   Case[/COLOR] 7: MsgBox "Run code for Russian"
   [COLOR=#0000ff] Case Else[/COLOR]: MsgBox "Run code for English (default)"
[COLOR=#0000ff] End Select[/COLOR]

[COLOR=#0000ff] Select Case[/COLOR] Application.LanguageSettings.LanguageID(msoLanguageIDUI)
[COLOR=#0000ff]    Case [/COLOR]1043: MsgBox "Run code for Dutch"
 [COLOR=#0000ff]   Case [/COLOR]1049: MsgBox "Run code for Russian"
 [COLOR=#0000ff]   Case Else[/COLOR]: MsgBox "Run code for English (default)"
[COLOR=#0000ff] End Select[/COLOR]

Or Maybe..... If Not English then.....do X

My company is Global so I may have to take into account several different language types....
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Fresh off the presses....

Slicer Naming convention in English:
Code:
 [COLOR=#0000ff]With[/COLOR] ActiveWorkbook.SlicerCaches("Slicer_" & Replace(strSlicerName, " ", "_")) [COLOR=#008000]'Replaces spaces with underscores[/COLOR]

Slicer Naming Convention in Spanish:

Code:
[COLOR=#0000ff]With [/COLOR]ActiveWorkbook.SlicerCaches("[COLOR=#ff0000]SegmentaciónDeDatos_[/COLOR]" & Replace(strSlicerName, " ", "_")) [COLOR=#008000]'Replaces spaces with underscores[/COLOR]

Got a win for the client :) .....as usual my gut was wrong ahahah


Is there a dynamic way to change this hard coded naming convention?

Instead of "Slicer_" then name used in X country.... or set the object earlier in the code?
 
Last edited:
Upvote 0
This should fix the issue for all languages....use the index instead of the word.
Code:
      SlicerIndex = SlicerIndex + 1                     
      [COLOR=#0000ff]With[/COLOR] ActiveWorkbook.SlicerCaches(SlicerIndex)

You live and you learn...
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top