Macro only works for english excel version - excel

I've a quick question for one of my vba codes , the code is basically consolidating 12 tables into one sheet called temp range B8. The problem is that if I run it using Excel 2016 English version it works fine on any computer but if the excel is 2016 spanish version , it will fail with error: " Execution Error 1004"
I've created 12 modules with macros and only one is failing using the spanish version for the following code
Range("B8").Consolidate Sources:=Array( _
"Enero[#All]", "Febrero[#All]", "Marzo[#All]", "Abril[#All]", "Mayo[#All]", "Junio[#All]", "Julio[#All]", "Agosto[#All]", "Septiembre[#All]", "Octubre[#All]", "Noviembre[#All]", "Diciembre[#All]" _
), Function:=xlCount, TopRow:=True, LeftColumn:=False, CreateLinks:=True

Changing the reference type from #All to #Todo was the fix , I-m good now

I'm glad you found a solution to your problem for the Italian version of Excel.
Perhaps, you could make some changes to your code so it could handle both cases (English and Italian). For instance, you could use the following function that returns the MsoLanguageID for Excel (inspired by this answer):
Function ExcelLanguage() As MsoLanguageID
ExcelLanguage = Application.LanguageSettings.LanguageID(msoLanguageIDUI)
End Function
You could then use an if-statement to handle both cases like this:
If ExcelLanguage = msoLanguageIDItalian Then
Range("B8").Consolidate Sources:=Array( _
"Enero[#Todo]", "Febrero[#Todo]", "Marzo[#Todo]", "Abril[#Todo]", "Mayo[#Todo]", "Junio[#Todo]", "Julio[#Todo]", "Agosto[#Todo]", "Septiembre[#Todo]", "Octubre[#Todo]", "Noviembre[#Todo]", "Diciembre[#Todo]" _
), Function:=xlCount, TopRow:=True, LeftColumn:=False, CreateLinks:=True
Else
Range("B8").Consolidate Sources:=Array( _
"Enero[#All]", "Febrero[#All]", "Marzo[#All]", "Abril[#All]", "Mayo[#All]", "Junio[#All]", "Julio[#All]", "Agosto[#All]", "Septiembre[#All]", "Octubre[#All]", "Noviembre[#All]", "Diciembre[#All]" _
), Function:=xlCount, TopRow:=True, LeftColumn:=False, CreateLinks:=True
End If
For all the MsoLanguageID values, see MSDN Documentation.

Related

Use the text of a cell as the argument of range() with structured references

I want to execute an advanced filter with vba. The problematic step is that the name of the source table (for the advanced filter) is written in a cell and it seems I can't find a way to pass it to range().
Here is the idea:
The F5 cell contain "DatePlace" and it is the name of the table that should be used in the advanced filter. By recording a macro I saw that we could use structured references in VBA but when I try to take the reference from the value of F5, the advanced filter doesn't execute anymore.
I receive this error message box (translated from french) :
Execution error '1004':
Error defined by the application or by the object
Here is one of my attempts :
Worksheets("Planning")
.Range(Worksheets("Macro").Range("$F$5").Text & "[[#Headers],[#Data]]")
.AdvancedFilter Action _:=xlFilterCopy,
CriteriaRange:=Worksheets("Planning").Range("E7:F8"),
CopyToRange:=Worksheets("Planning").Range( _"E11:F11"), Unique:=False
I tried with .Value instead of .Text. I tried to pass it with a string variable too. I also tried to write the full reference in the F5 cell. And when I tried to get a range variable I just moved the issue to that variable initiation.
Any help is welcomed.
Edit 1 :
This way of doing it works but I have to hard code the structured reference and that's exactly what I want to avoid.
Worksheets("Planning")
.Range("DateLieu[[#Headers],[#Data]]")
.AdvancedFilter Action _:=xlFilterCopy,
CriteriaRange:=Range("A6:B7"),
CopyToRange:=Range( _"A10:B10"), Unique:=False
Edit 2 :
It should have worked without issue. Here is how the code looks now.
' Variables
Dim rngPlanning As String
' Initiations
rngPlanning = ThisWorkbook.Worksheets("Macro").Range("$F$5").Text & "[[#Headers],[#Data]]"
' Actions
Application.CutCopyMode = False
Debug.Print (rngPlanning)
Worksheets("Planning").Range(rngPlanning).AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=Worksheets("Macro").Range("$E$7:$F$8"), _
CopyToRange:=Worksheets("Macro").Range("$E$11:$F$11"), _
Unique:=False

How to get a specific statement from a PDF using selenium with VBA

This is a continuity question of the below link. https://stackoverflow.com/a/56649098?noredirect=1
I need to do two things
1. Copy all text from PDF and paste it to the excel
2. Copy multiple lines and run a loop to find the text I need
The background of my project - I am opening a webpage with user credentials, after couples of clicks a PDF is opened in the browser. So now I need to get a particular statement from it. The problem is that the PDF is dynamic and the statement I require keeps changing (the line sometimes it is in 6th and sometimes in 9th or 10th and 11th) so the 2 things which I mentioned above will help me I am aware both sounds the same but it is different. Below is the code I used to get a particular statement, but how do I create a loop through all the statement or get multiple statements.
Const statext As String = _
"addEventListener('message',function(e){" & _
" if(e.data.type=='getSelectedTextReply'){" & _
" var txt=e.data.selectedText;" & _
" callback(txt && txt.match(/[^\r\n]+/g)[7]);" & _
" }" & _
"});" & _
"plugin.postMessage({type:'initialize'},'*');" & _
"plugin.postMessage({type:'selectAll'},'*');" & _
"plugin.postMessage({type:'getSelectedText'},'*');"
Casestatus = bot.ExecuteAsyncScript(statext)
I am very new to programming and automation so I may be missing a basic thing. Kindly pardon me.

Excel User-defined functions can't use ArgumentDescriptions in Excel 2007. I'm trying to bypass it in my Add

I have created a couple of user-defined functions in Excel and created a simple add-in so that I can share them with colleagues.
I use Application.MacroOptions in order to give some useful indications for how to use the functions. Especially, I use ArgumentDescriptions to give descriptions for the arguments.
Application.MacroOptions _
Macro:=FuncName, _
Description:=FuncDesc, _
Category:=Category, _
ArgumentDescriptions:=ArgDesc _
HelpFile:= Helpfile
I have just found out that the ArgumentDescriptions parameter is not supported in Excel 2007 and this is causing an error for this version. Excluding this parameter solves the problem.
I don't want to have to distribute two versions of the add-in. I tried to use this code to include the parameter if the version more recent than Excel 2007, but it still gets tripped up on the unrecognized parameter name if used in Excel 2007:
If Left(Application.Version, 2) > 12 Then
Application.MacroOptions Macro:=FuncName, ArgumentDescriptions:=ArgDesc
End If
Is there a way to solve this problem so I can do this all with just one add-in?
Thanks
An easy way to get around the Named argument not found error in the your function is to move the setting of the macro options into 2 separate functions:
If Left(Application.Version, 2) > 12 Then
setUpNewMacroOptions
Else
setUpOldMacroOptions
End If
And then the 2 functions:
Public Sub setUpOldMacroOptions()
Application.MacroOptions Macro:="myMacro", Description:="desc", Category:="cat", HelpFile:="file"
End Sub
Public Sub setUpNewMacroOptions()
Application.MacroOptions Macro:="myMacro", Description:="desc", Category:="cat", ArgumentDescriptions:="blah", HelpFile:="file"
End Sub
As the setUpNewMacroOptions function is never called in Excel 2007, the VBA compiler doesn't try to validate the function so no error.
This procedure works in Excel 2010 with argument descriptiors and in 2007 without them:
Private Sub AddDesc(Macro As String, Description As String, _
Category As String, ArgumentDescriptions As Variant)
#If VBA7 Then 'in Excel 2010 and over
Application.MacroOptions Macro:=Macro, Description:=Description, _
Category:=Category, ArgumentDescriptions:=ArgumentDescriptions
#Else 'in Excel 2007 and under
Application.MacroOptions Macro:=Macro, Description:=Description, _
Category:=Category
#End If
End Sub
Best regards,
Peter Krassoi

Excel VBA , code runs one one version of office but not in other?

I have the following code written on excel 2013 english and it works fine. but when i run it on excel 2007 german, it stuck on this line (if rngFrom.... 3rd line on the code) How can I solve this?
For j = 1 To rngFrom.Cells.Count
rngTo.Cells(j).Value = rngFrom.Cells(j)
If rngFrom.Cells(j).DisplayFormat.Interior.Color <> rngFrom.Cells(j).Interior.Color Then
rngTo.Cells(j).Interior.Color = rngFrom.Cells(j).DisplayFormat.Interior.Color
End If
Next j
but when i run it on excel 2007 german, it stuck on this line (if rngFrom.... 3rd line on the code) Any idea..how i can solve this?.
Range.DisplayFormat Property was added from xl2010+ onwards.
Please see THIS MSDN link.
Quote form that link (In case the link dies off):
EDIT:
I believe what you are trying to compare the conditional formatting color with the cells' interior color. If yes then you can use this code as well
For j = 1 To rngFrom.Cells.Count
rngTo.Cells(j).Value = rngFrom.Cells(j)
If rngFrom.Cells(j).FormatConditions(1).Interior.Color <> _
rngFrom.Cells(j).Interior.Color Then
rngTo.Cells(j).Interior.Color = _
rngFrom.Cells(j).FormatConditions(1).Interior.Color
End If
Next j
I am assuming that there is only one condition in the conditional formatting.

Downloading excel file name based on date Macro

I'm trying to write a macro that downloads data into a file, where the file name contains yesterdays date.
"TEXT;http://www.mydomainname.co.uk/price_spiders_competitors_prices_gb/GBPS AEG " & Format(Today() - 1, "yyyy-mm-dd") & " higher_than.csv" _
, Destination:=Range("$A$1"))
This isn't working
"TEXT;http://www.mydomainname.co.uk/price_spiders_competitors_prices_gb/GBPS AEG 2013-02-06 higher_than.csv" _
, Destination:=Range("$A$1"))
This does!
Any ideas, I have a feeling the dashes are causing an issue but it also doesn't seem to like my Today -1!
Thanks for any help
Try function 'Now()' instead of 'Today()' to get the current date and time.
As far as i know, excel doesn't have the function 'today()' in VBA. You can use 'today()' in a formula but not in VBA.

Resources