"→"-Character in Office 2013 Excel VBA not copyable into Code - vba

I'm currently programming a VBA Code for iMacros,
therefore I need to have the following string:
TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=TXT:Find<SP>Facebook<SP>ID<SP>→
but, if I copy this code into the VBA Code Editor in Excel 2013, I get the following:
TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=TXT:Find<SP>Facebook<SP>ID<SP>?
The character → is not readable for VBA and rewrites it as a ?
I would use the string like this in my code, to send it to iMacros:
macro = macro + "TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=TXT:Find<SP>Facebook<SP>ID<SP>→" + vbNewLine
How can I still send the right string to iMacros?
I tried to add the character as a Hexadecimal number to add it to the string, but didn't figure really out how it could work..
Do you have any idea how I can use the character → in VBA?

Simply use:
macro = macro + "TAG POS=1 TYPE=BUTTON:SUBMIT ATTR=TXT:Find<SP>Facebook<SP>ID<SP>" & ChrW(8594) & vbNewLine
;)
Hint: The "compiler" simply does not support double byte characters (still they can be inside a string). And ChrW(8594) is →. If you get problems with other chars, you can use ?AscW(Range(#)) (# is the cell that has that character at the first position) to get the code for ChrW() to recreate it.

Related

How to remove hidden quotes

I've Excel sheet that has few text columns. These text columns are Email Messages. The data from this sheet will be used to send mails.
There data looks fine in Excel but when the message is copied to the Email body quotes are appearing in the beginning and end of the message.
I researched online and found out that these are unwanted characters. I tried removing the " using following formula.
=SUBSTITUTE(SUBSTITUTE(CLEAN(K1),CHAR(127),""),CHAR(160),"")
However the problem is that there are multiple columns with this problem so this method is not very feasible option for me. Also another problem is that after this the cell loses the formatting.
Please help me resolve this, I'm looking for a Find and Replace method if possible. Worst case scenario would be a macro.
Thanks in advance.
Cells.Replace What:=Chr(127), Replacement:=vbNullString
Cells.Replace What:=Chr(160), Replacement:=vbNullString
Your cells in your excel sheet contains multiple lines of data within a data, which means all lines in the cell are entered with carriage return. (Enter Key)
If you copy and paste such cells to a txt file, you will get the text within a " ". The " " are not actually quotes, but text with carriage return.
Just use the formula and let me know if it works,
=SUBSTITUTE(A1,CHAR(10)," ")

Plus sign in front of Time. Assigning formula to cell in VBA

I have time (hh:mm) cell in Sheet1 and I'd like to show it's value in Sheet2 prefixed with a plus sign (+00:01).
I came up with ="+"&TEXT(Sheet1!$A$1, "hh:mm"). It works fine but I don't know how to code it in VBA.
I have this so far:
result_cell.Formula = "=""+""&TEXT(" & ?????? & ", ""hh:mm"")"
I have no idea what should go in place of question marks.
Firstly, you can put the + inside the TEXT function
=TEXT(Sheet1!$A$1, "+hh:mm")
Now in VBA
result_cell.Formula = "=TEXT(Sheet1!$A$1,""+hh:mm"")"

MS Word, how to change formatting of entire paragraphs automatically in whole document?

I have a 20-page word document punctuated with descriptive notes throughout, like this:
3 Input Data Requirements
Some requirement text.
NOTE: This is a descriptive note about the requirement, which is the paragraph that I would like to use find-and-replace or a VBA script to select automatically and change the formatting to italicized. The notes invariably end in a carriage-return: ¶.
If it was just a text document, not MS-Word, I would just use a regex in a code editor like sublime to wrap it with <I>...</I> or something along those lines.
Preferably, is there a way to do this in Word's "advanced" find-and-replace feature? Or if not, what's the best way to do it in VBA?
I've tried using a search string like this in find-and-replace: NOTE: *[a-z0-9,. A-Z)(-]{1,255}^l but the line-break part doesn't seem to work, and the 255 char max isn't enough for many of the paragraphs.
EDIT: Another slightly important detail: The doc is automatically generated from another piece of software as a .RTF, which I promptly converted to .docx.
Attempt #2: Use Notepad++ to find and replace using regex. Remove quotes.
Find: "( NOTE: .*?)\r"
Replace with: " \i \1 \i0 \r "
//OLD
Sure is. No VBA or fancy tricks needed.
CTRL + H to bring up the replace dialog.
Click "More".
Select "Font" in the drop down menu called "Format".
Click italics.
Enter find and replace text as the same thing. Make sure you set this up right so that you don't accidentally replace substrings (e.g. goal to replace all " test " with " nice ", testing -> niceing).
Should work. If you need to alter entire paragraphs, consistently, then you probably should have used the styles on those paragraphs to begin with. That way, you can change all of them at once by updating the style itself.
You can use Advance Find, yes. Find Next and then Replace makes the selection Italic.

Excel - Inserting formula with VBA

Hello Stackoverflow friends,
I am struggling for 1 hour with a formula I would like to insert via VBA:
Formula = "=IFERROR(VLOOKUP(Q" & j & ";Table1[#All];2;FALSE);"""")"
ThisWorkbook.Worksheets("Sheet1").Cells(j, "AE").FormulaArray = Formula
I get the following error message:
Run-time error '1004' - Application-defined or object-definied error
Is there an issue with the brackets or double quotes?
Thanks!
Replace the semicolons with commas:
Formula = "=IFERROR(VLOOKUP(Q" & j & ",Table1[#All],2,FALSE),"""")"
OpenOffice uses semicolons to separate function parameters, Excel normally uses commas, and always uses commas when setting formulas in the above fashion.
When programming in any lanugage also in VBA - better not tied up user to specific regional settings or specific excel version.
So instead of this:
Formula = "=IFERROR(VLOOKUP(Q" & j & ";Table1[#All];2;FALSE);"""")"
ThisWorkbook.Worksheets("Sheet1").Cells(j, "AE").FormulaArray = Formula
Better use this approach, when you determine exact user environment:
s = Application.International(xlListSeparator)
Formula = "=IFERROR(VLOOKUP(Q" & j & s +"Table1[#All]" + s + "2" + s + "FALSE)" + s + """"")"
ThisWorkbook.Worksheets("Sheet1").Cells(j, "AE").FormulaArray = Formula
p.s. I didn't checked the formula for the brackets etc. but just indicating the correct usage of list separator, and how to insert formulas with VBA code within cells in correct way.
As well, as previous post says - excel probably change the formula automatically when you open it. However excel do not change VBA code automatically, so be aware and pay attention to proper code in VBA.
Depending on the regional settings, the list separator (which is also used to separate parameters in functions) is either the semicolon or the comma. This applies when typing a formula into a cell.
Excel dynamically adjusts the list separator (and function names) according to the regional settings of the current computer when a file is opened.
So, if a user with German regional setting, which have the list separator ; saves a file, then a user with US regional settings and a list separator , opens the same file, Excel will adjust the German list separators in the formulas automatically.
When writing VBA, though, you will always need to use the US-English conventions for the list separator, which is the comma.

Formatting text from Mulitline text box in word with VBA

I'm putting together a template in Word, using a form for the user to fill in to then populate some of the document.
The bit I'm currently stuck on is at the end of the document, where the cc's are listed.
The form has a multiline text box into which the user puts in their cc's, one per line.
I then want to add to the end of the document the contents of the text box, but in the right format. Specifically, it should look like:
cc: First CC contact
Second CC contact
so on and so forth
I attempted to do this using 2 bookmarks, so my code currently is:
' If 'CC' box has content, add it
If doc_CC.TextLength > 0 Then
.Bookmarks("CC").Range.Text = vbCr + "cc:"
.Bookmarks("CCs").Range.Paragraphs.Indent
.Bookmarks("CCs").Range.Text = doc_CC + vbCr
End If
However, when this is run, on the page it looks like:
cc: first contact
second contact
and so on
Realise that the 2 bookmark method is a bit messy but it seemed like a good idea at the time - obviously this is not the case! Have done some searching for a way to do it with Split but am not making much progress down this path - suspect I'm googling for the wrong thing.
How do I do this so that the formatting is as desired? Any help is greatly appreciated.
Try inserting a tab character? + Chr(9) or even + vbTab may work.
Have found a work around which, while doesn't answer the actual question of how to do it, does produce a result to the same effect.
Have used a 2 column table without no lines instead with contents of a1 being "cc:" and contents of a2 being whatever was entered into the multiline text box. If there is nothing in the text box, then the table is deleted.
I'll keep on eye on this question though so if some one does have the proper answer I can mark it accordingly.
Another possibility would be to format the cc paragraph with a hanging indent (like is used for bullets or numbering). Use a newline character - Chr(11) - instead of vbcr to separate each entry. The text should all line up,then...