I have an Excel file and a userform where user can type in students' details and the form will check for duplication and then add the info onto the last line of a table. I want to improve it further by making the form capitalize the first letter of each name using this code:
Me.Surname.Value = StrConv(Me.Surname.Value, vbProperCase)
Me.Surname.Value is the input of the form, mostly Vietnamese such as Trần, Nguyễn, Thảo, etc. However, they are changed into something like Tr?n, Nguy?n, Th?o after going through StrConv. I read some suggestions and change my locale to Vietnamese but the problem persists.
Do you have any suggestion to fix this? I am thinking of converting the inputs into hex value and then write them down using ChrW(), but I can't find a way to do that.
I played a bit with this and the culprit seems to be StrConv.
It works for me if instead of using StrConv I explicitely set the proper case:
Surname.Text = UCase(Left(Surname.Text, 1)) & Mid(Surname.Text, 2)
or even more precise:
Surname.Text = UCase(Left(Surname.Text, 1)) & Mid(LCase(Surname.Text), 2)
Related
I have a Macro that creates a Mailto Link with email addresses input in one cell, and the body of the email made up of 3 different cells, the mailto Strin in the code snippet. This link should then be placed into a certain cell.
With Sheets("Menu")
.Hyperlinks.Add _
anchor:=.Cells(row, 8), _
Address:=mailTo, _
TextToDisplay:="mailTo", _
ScreenTip:="MailTo link"
End With
However I sometimes get an
error 1004
in the above code. Removing parts of the email body resolves the issue so I originally thought that it might be related to the length of the mailTo String. However this does not seem to be the case since I've gotten it to work with different length strings.
What other possible reasons are there that could result in the Hyperlinks.Add function failing?
There could be any of several reasons. For example, Row may be 0:
There is a maximum worksheet hyperlink limit of 65536. You could be running up against this*.
If so, an alternative is to use Excel's HYPERLINK formala.
*(see https://support.office.com/en-us/article/Excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3?CorrelationId=6fdacf7e-c207-4932-a46d-b82e7fa0679b&ui=en-US&rs=en-US&ad=US&ocmsassetID=HP010342495)
It seems that there is a limit to how long the hyperlink can be, 2012 characters as returned by the len function.
The reason I didn't originally discover this was because I was only looking at the mail text before converting to a mailto.
The conversion replaces new lines and spaces with %0A and %20 respectively. So "Hello World" is 11 characters long but in the Mailto it would look like this "Hello%20World" and have a length of 13. Since I was looking at the Text before the conversion and adding/removing spaces it seemed to me like mailtos of different length where working.
Thank you for everyone that offered suggestions even though they weren't what I was looking for. I hope that this can be of help some one else in the future.
I am writing data into an excel spreadsheet. The data comes from an Access Database. Code like the line below works:
xl.cells(5,5)="joe"
but code like the line below does not:
xl.cells(5,5)="1/2CD438"
I get an error like "Application defined or object defined error"
I think Excel is trying to do a calculation, and the calculation fails. All I really want is the text string.
I've tried formating the column like
columns(1).NumberFormat="#"
, but it doesn't work either.
Any ideas?
Thanks for all the input. I had tried several of your ideas without success. As it turns out I was using variables to determine the exact row, column as:
xl.cells(NextRow, Col) = ars!PartNo
By simply replacing NextRow with an integer, the code worked. Replaced the integer in the test with NextRow, and the code ran. I suspect a misspelling or something, but couldn't see it looking at the code.
Thanks for the suggestions.
I cannot figure this one out.
We use mostly french-version Excel (as we live in a french-speaking province of Canada). Somewhere in VBA code I set a cell's formula directly. Normally, we have to write the formula in english and Excel does the translation (writing the formula in any other language than english in VBA results in an error as far as I know). However, only HALF of this equation is translated which I think is causing me issues (writing the correct formula in another cell yields different results and most probably right results).
range("J2").Formula = "=round(IF(F2="",0,F2),2)-round(IF(G2="",0,G2),2)"
Is translated to this in the cell:
=ARRONDI(SI(F2=",0,F2),2)-round(IF(G2=",0,G2),2)
As you can see, the right part should read "ARRONDI(SI(.." but it does not read that way. I have tried adding spaces, removing the minus sign altogether, etc. Nothing works, it's always half translated. Any idea ?
In VBA you neexd to escape your quotations like this:
range("J2").Formula = "=round(IF(F2="""",0,F2),2)-round(IF(G2="""",0,G2),2)"
This is because the " Character is used in VBA as the start / end of a string. So if you want ot include it IN a string you need to type it twice in a row.
I need to add a subscript (a little number next to a character, like 2 or 3 - note: not a power of...) to a string [variable]. Is this possible? I don't want the code to be lengthy as I will need to process a lot of formulas, one at a time. Thanks.
You will have to use the character set subscript numbers. Strings do not contain formatting.
http://www.fileformat.info/info/unicode/char/2082/index.htm
Is this possible? No - string variables do not contain formatting.
In order to achieve this you will need to add some sort of formatting to your string and display it in something that can show different formats - for example a RichTextBox control
Try adding a RichTextBox control and running the following line:
RichTextBox1.Rtf = "{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\fnil\fcharset0 Segoe UI;}}\viewkind4\uc1\pard\ltrpar\sa200\sl276\slmult1\f0\fs22 sometext\fs12 subscript\fs22\par\pard\ltrpar\f1\fs17\par}"
I don't claim to know what all the formatting is in here so I will leave you to figure that out yourself - hope that helps...
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...