What I intend to do:
I have a User Form where the user can select from a list of languages which is based on the possible languages in vba (https://learn.microsoft.com/de-de/office/vba/api/office.msolanguageid). For this I have just removed the "msoLanguageID" part. Once the user has chosen the language and confirms, I would like to set the language for a selected / all slides.
What I have done:
I take the country name from the UserForm and add the "msoLanguageID" part back again (and remove any spaces in the string). So the name is exactly the same as in the list.
Language_ID_String = "msoLanguageID" & SELECTED_LANGUAGE_WITHOUT_SPACES
The challenge:
When setting the default language either an attribute of type "MsoLanguageID" or the language ID (integer) is required. So the string I have created won't work.
Where I need help:
Is there a way to convert the string into the type "MsoLanguageID"? Otherwise I assume I need to match the country back to the ID.
Thanks for your help!
Related
Im going to try to make this as simple as i possible can. I work in a shipping company, where we email our clients if there is any issues with their orders. I have recently made a vb.net program that standardizes these emails. Now i am rewriting the program so that the templates can be edited from a text file. right now they are hard coded into the program itself.
SO, this is what im wanting to do
Template.txt -> Good afternoon %NAME% your order has shipped.
I want the program to open this text file, Change %NAME% to variable CustName which is entered from a text box, Then show the updated text in a RichTextBox. But i dont want the template.txt to save the changes.
Was wondering if you fine people could help me out with this.
Thanks a lot!
The first answer is on the right track. You just need to store the template text in your file. With this in your text file:
Good afternoon {0} your order has shipped.
you can then do something like this:
Dim name = "someone"
Dim template = File.ReadAllText("TextFile1.txt")
RichTextBox1.Text = String.Format(template, name)
The first argument to String.Format is the template, containing the numbered placeholders. The remaining arguments are the values to replace those placeholders. The first of those arguments will replace every instance of "{0}" in the template, the second will replace "{1}" and so on. You need to make sure that your numbered placeholders always match the order of the values you pass to String.Format.
If you don't want the person editing that template to have to remember what each number means, you can write your own replacement code. For instance, you might store this in the file:
Good afternoon {name} your order has shipped.
and then do this:
Private Function FillTemplate(template As String, name As String) As String
Return template.Replace("{name}", name)
End Function
and this:
Dim name = "someone"
Dim text = FillTemplate(File.ReadAllText("TextFile1.txt"), name)
RichTextBox1.Text = text
You need to add a parameter and a Replace call to FillTemplate for each value you want to insert, e.g.
Private Function FillTemplate(template As String,
name As String,
address As String) As String
Return template.Replace("{name}", name).
Replace("{address}", address)
End Function
I think the syntax you're looking for is something like
String.Format("Good afternoon {0} your order has shipped", name_variable)
If you wanted to change two pieces of information, you could use
String.Format("Good afternoon {0} your order has {1}", name_variable, "shipped")
Basically I have created an acronym finding macro and it works well except it includes all of our reference numbers. Now unfortunately changing the search parameters won't work as many acronyms include both letters and numbers.
My idea was to compare the string, once found, and if it is in the reference number format e.g.
LetterNumberNumberLetterLetterNumberNumberNumberNumber
I will simply not include it.
I'm certain there must be a simple way of doing this and me not being able to locate it is a case of not knowing what to search for but anyway thank you in advance for the help.
Use LIKE:
'//LetterNumberNumberLetterLetterNumberNumberNumberNumber
if ucase$("A12BC3456") like "[A-Z][0-9][0-9][A-Z][A-Z][0-9][0-9][0-9][0-9]" then
msgbox "is ref no."
I have a spreadsheet where the user inputs various details on an inputs page and then presses a calculate button to get what they want. The inputs are strings, numbers and dates.
I want to save the inputs for each calculation for the user so that at a later date they could enter the calc id and not have to renter the inputs.
One simple way I thought of doing this was to copy the inputs when the calculation is run to another sheet with the inputs in a column with the calc id. Then just save future inputs in a separate column and lookup the correct column to retrieve the inputs at a later date.
I read this question - What are the benefits of using Classes in VBA? and thought it would be good to make a class called CalculationInputs that had all the details stored in one object. This may be overkill for what I need but i wanted to ask how other people would solve this simple task.
You can use Names to define variables within the scope of a workbook or worksheet. Typically these are used to define ranges, and more specifically dynamic ranges, but they can also be used to store static/constant values.
To create a Name manually, from the Formula ribbon, Names Manager:
Click on the "New" button, and then give it a meaningful name:
Make sure you put ="" in the "Refers To" field, if you leave it blank, the name will not be created.
Then when you press OK, or any time you go to the Names manager, you will see a list of all available Names in the workbook.
You can edit these through the Names manager, which is probably tedious, or you can easily use VBA and inputs to control them, for example:
Sub Test()
ActiveWorkbook.Names("MyAddress").RefersTo = "734 Evergreen Terrace"
End Sub
You could do something like this to capture the value, our use other macros or user firm code to assign the value to the Name.
Activeworkbook.Names("MyAddress").RefersTo = _
Application.Inputbox("please enter your address")
Etc.
If you run this, and then review the Names manager, you'll see the value has been updated:
In VBE, you can refer to the name like:
Debug.Print ActiveWorkbook.Names("MyAddress").Value '# Prints in the immediate pane
Range("A1") = ActiveWorkbook.Names("MyAddress").Value
These can also be accessed (read) from the worksheet, like:
I am fairly new to VBA (Word 2010) and I'm unsure if something I'd like to do is even possible in the way that I want to do it, or if I need to investigate completely different avenues. I want to be able to print ranges (or items) that are not currently enumerated as part of either wdPrintOutRange or wdPrintOutItem. Is it possible to define a member of a wd enumeration?
As an example, I'd like to be able to print comments by a particular user. wdPrintComments is a member of the wdPrintOutItem enumeration, but, I only want comments that have an Initial value of JQC. Can I define a wdPrintCommentsJQC constant? My code is reasonably simple; I have a userform that lets the user pick some settings (comments by user, endnotes only, etc.) and a Run button whose Click event should generate a PrintOut method with the proper attributes. Am I on the wrong track?
(If it matters, the Initial values will be known to me as I write the code. I have a discrete list.)
No, it's not possible to add a constant to a predefined enumeration type.
However, one possible way to do this would be to build a string of page numbers which contain the items you wish to print, open the print dialog in the "dialogs" collection, and set it to print a specified range, andinsert the string containing the list of pages (separate them with commas). Finally, execute the .show method of the print dialog to show it to the user and give them the opportunity to set any other items and click the "ok" button. I've done something very similar when I needed to print a specific chapter of a long document, and so I had to specify the "from" section and page and the "to" section and page for the user. Below I just show how to specify a list of pages instead of the ".form" and "to" I was using:
With Dialogs(wdDialogFilePrint)
.Range = wdPrintRangeOfPages
.Pages = "3,5,7-11"
.show
end with
I'm not sure how you want to print the comments (or other elements), but you could create another document and insert what you want to print on this document.
According to what you want, you could insert them as they were (comments, footnotes, etc) or as plain text, or any other format.
I am looking for logic that converts an incorrect user input to a correct integer input.
For example, a user might mistakenly type in letters within an integer input and the logic changes that input to the correct form(integer).
Any ideas?
If you want only numeric values, you can use a numeric control instead of textbox (NumericUpDown if I remember correctly). Otherwise, you can listen to the OnKeyDown or OnKeyPress event, "see" what's inside the argument (the key typed by the user) and eventually change its input. For instance, I'm in Italy and often users use . or , for decimal separator. So I translate dot to comma while the user types. Also, when a non-number is typed, I set e.Cancel to true so nothing is appended to the text displayed.
For typing errors, a BK tree is often used, in conjunction with Levenshtein Distance. Here is a good explanation on how this is applied.
Why would you correct incorrect input? You would want to prompt the user to re-enter the information correctly and tell them to enter an integer.