A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Thank you very much for your effort CDN-Carl,
I can see we had similar ideas, I also tried something like WasteTime subroutine before I found out it interferences with hyperlinks.
I also thought about using global variable but resetting of the gVariable in my project would become similar technique as to keep an eye on order in which addLink and addValidation are called and that is not practicable in such big project due to a lot of subroutines, possible different orders and stuff. It could happen that gVariable is reset unintentionally and broken validation list appears.
However I kept playing with Excel and found another solutions in case global variable cannot be used:
Solution 1
Application.Run. I don't know the entire process how exactly it works behind the scene but I found out that calling the procedure with Run command surrounds the procedure outside with its own list separator state, so a default list separator (comma) is used even when executed after hyperlink, instead of regional list separator (semicolon).
' Continues procedures from original post with no changes
Sub runWrong_UsingRun1()
Application.Run "addLink"
addValidation
End Sub
Sub runWrong_UsingRun2()
addLink
Application.Run "addValidation"
End Sub
Doesn't matter if Application.Run is used for addLink or addValidation procedure, both variants returns correct result.
Solution 2
A little tweak of addValidation procedure. It puts a validation in the Cell, then reads its content back. I have found that reading the content of Formula1 parameter returns semicolons (regional list separator) instead of commas (default list separator). If there is not the right list separator, modify the validation using the right one.
' Continues procedures from original post with no changes
Sub addValidation2()
With Range("A1").Validation
.Delete
.Add xlValidateList, Formula1:="one,two,three"
If InStr(1, .Formula1, ",") > 0 Then .Modify Formula1:=Replace(.Formula1, ",", ";")
End With
End Sub
Sub runOk2()
addValidation2
addLink
End Sub
Sub runWrong2()
addLink
addValidation2
End Sub
Both runOk2 and runWrong2 returns the correct result. Procedure runOk2 calls addValidation2 subroutine, puts validation (one,two,three) into Cell, reads it back (one;two;three) and goes to End Sub. When procedure runWrong2 calls addValidation2 subroutine, puts validation (one,two,three) into Cell, reads it back (one,two,three) and the Replace function is executed.
Drawbacks
Any idea of significant drawbacks of the solutions?
Thank you CDN-Carl for your time and help.