JavaScript Eval to replace empty spaces with <SP>, literal - vba

I am using iMacros & VBA. I created a string in VBA that replaces empty spaces with <SP> so I can pass it to an iMacros script. The problem is iMacros takes the <SP> as a space and not as a string. I tried to tweak VBA but when its passed to iMacros as a variableits just empty spaces.
i figured I try to do an eval in iMacros directly but am stuck with the proper syntax.
Set Name "Chris Tony James"
Set newName EVAL("\"{{Name}}\".replace(/ //g, \"<SP>\";")
i have tried a million varieties, even using split.join. I just cant get it.
thanks for any help
Before: Chris Tony James
After: Chris<SP>Tony<SP>James

It must be something like that:
Set newName EVAL("\"{{Name}}\".replace(/\s+/g, \"<SP>\";")

Set Name Chris<SP>Tony<SP>James
Is all that is required to use <SP> in place of spaces in a variable in iMacros. Omit the " marks.

Related

Reading a line from the clipboard in vb.net not matching text

I am trying to read from the clipboard and place in an array. I want to validate the first line as the text: "Client Code "
I fill the array with:
tbClipBoardContents.Text = My.Computer.Clipboard.GetText()
For Each strLine As String In tbClipBoardContents.Lines
arrClipBoard.Add(strLine.ToString)
Next
When I give a variable the value of the first array entry it appears correct = "Client Code " in Visual Studio debugging.
Dim test As String = Trim(arrClipBoard(0).ToString)
However when I check using the "IF" statement it tells me it is not correct??
If test = "Client Code " Then
MsgBox("Correct Clipboard Structure")
Else
MsgBox("Not a Valid Clipboard Structure: " & Trim(arrClipBoard(0).ToString)) ' ** Fires this response.
End If
What is doing my head in is that if I copy the value of test from VS debugger and paste it in the if statement it looks like "Client Code " but this time the if statement fires the correct response.
I have tried it by filling the textbox (tbClipBoardContents) using:
tbClipBoardContents.text.split(New [Char]() {CChar(vbCrLf)})
and
tbClipBoardContents.text.split(newvbline)
with the same results.
So does this mean the true value from the clipboard for the line "Client Code " also carries some hidden characters? Any help is appreciated.
Brad
P.S. I have found that if I test the value of Mid(test,1,11) then I will get the desired result, so this is a workaround but would be interested to know what the 12th character is? Perhaps it is the "CChar(vbCrLf)"
As per my observation Trim will have removed the spaces. and you should change the condition to "ClientCode".
The final solution that worked for me was to find the trailing space using Andrew Morton's method above then
arrClipBoard.Add(Trim(Regex.Replace(strLine.ToString, Convert.ToChar(160), "")))
which effectively converted the char(160) to "".

How can I use special chars in VBA of Microsoft Word?

I've created a set of macro files in Microsoft Word's VBA as a sort of a CAT tool (CAT = https://en.wikipedia.org/wiki/Computer-assisted_translation). The problem is that there are cases where I display the text needed to be translated and the user needs to input text in his own language. That might include some special chars, like "ăîâșț/ĂÎÂȘȚ", or even quotes or brackets. Is there any way to use those in some InputBox function? Or, at least, some way to let the user input the text he needs in some TextBox or something?... Or how should I approach this?... Maybe UTF-8 support would be what I need? Or?... Any help would be appreciated!...
I've tried Microsoft Word's vba function InputBox. I'm also thinking if, maybe, I would be able to create my own InputBox, with my conditions on it, I might be able to have one that accepts those chars too, or all the chars into some string variable... Here is something someone on StackOverflow says:
Is it possible to create an 'input box' in VBA that can take a text selection with multiple lines as an input? (I'm referring to gizlmo's answer...)
Here are 3 lines of code that contain that (although it's more of a how to question, not a debugging question, so those are not really needed...)
MsgBox ("Ziua " & Str(ziua) & " - " & titlurien(ziua))
titluales = InputBox("Titlul original: " & titlurien(ziua), "Ziua: " & Str(ziua) & ", Rapsodia Realitatilor " & monthname(lunanecesara) & Str(annecesar))
titluriro(ziua) = titluales
I expect the output to be exactly what he typed, whether it's quotes, brackets or special characters (like "ăîâșț"/"ĂÎÂȘȚ")...
A VBA InputBox will take any character typed or pasted into it. The characters available to type depends on the Language version of Windows and Office that the end user has installed.
Below is a test I just made with your example character string "ăîâșț/ĂÎÂȘȚ"
SpecialCharInput()
Dim str As String
str = InputBox("Enter you text", "Special Test Input Box")
Debug.Print str
End Sub
On my English language system, the only trouble it had was with the upper and lower case "ȘȚ" Turkish characters. By trouble I mean it turned those characters into question marks "??" in the result string. I'm sure though, if my system supported the Turkish language that those characters would be recognized and outputted properly.

VBA Hyperlinks.Add method prepending local folder to Address

I've been lurking here for a while but this is my first post so let me know if I need to change something. Anyways, here goes:
I'm trying to create a macro that will add hyperlinks to cells in a worksheet. The problem is that after running the macro, I notice that the folder location of my spreadsheet has been prepended to the address that I specified. Is there something I need to do in order to indicate that this is a webpage and not a local file? Excerpt from the macro is below.
Dim IGQ As Range
Dim IGQno As String
Dim IGQno1 As String
For Each IGQ In Range("A2:A10") 'Actual range is much larger
IGQno = IGQ.Value
IGQno1 = Left(IGQ, 1)
Sheets("Cameron DCDA").Hyperlinks.Add Anchor:=IGQ, _
Address:="""http://xxxx""&IGQno1&""xxx""&IGQno&""xxxxx""" 'It's a company website so they probably don't want me to share it
Next
The result is that a hyperlink is created for each cell but it links to file:///C:\Users\John.Doe\Documents\"http://xxxx"&IGQno1&"xxx"&IGQno&"xxxxx"
I've tried using fewer quotation marks in the address since it seems like overkill but I get the compile error "Expected: end of statement"
Do you guys have any suggestions?
Too many quotes
Address:="http://xxxx " & IGQno1 & "xxx" & IGQno & "xxxxx"
Also - be sure to leave a space before your & otherwise it will be interpreted as a variable type suffix:
What are possible suffixes after variable name in VBA?

How to use a cell's value for part of a cmd argument in VBA

I am trying to use a cell's value (a path, in this case) as part of a cmd argument in VBA.
My three tests to execute cmd lines from VBA.
Test1 and Test2 work perfectly, but I cannot get Test3 to work. Is this a syntax issue, or how might I otherwise get VBA to execute the line how I want it to?
Here is the screenshot for reference:
Thank you!
Your quotation marks appear to be in the incorrect place for the call to perform as desired. Change that line to Shell ("cmd /c hostname > " & Range("A3")) and it should work as intended
Yes this is a syntax issue, as you enclose the command in speech marks "" there is a break where you use speech marks within your command.
In order to get around this you need to use double speech marks within your string:
Shell ("cmd /c hostname > Range(""A3"")")

how to do reverse index in VBA

I don't know anything about VBA but I need to get the file name out of a file full path.
So for a string like "c:\something\somethingelse\file.name" I need to get "file.name" out. Also how can you get a quote in a string such as " " "? backslash doesn't seem to work.
To get a quote in a string use two quotes ("")
To find the location of the slash from the end, use InstrRev()
the DIR() function will return the filename.
You need to add a reference to the Microsoft Scripting runtime.