Word Vba : how to get the name of a style in foreign language - ms-word

"Heading 2" style in French is "Titre 2": how to get "Titre 2" knowing "Heading 2" ?
I searched on Google and found this
https://msdn.microsoft.com/en-us/vba/word-vba/articles/style-namelocal-property-word
Unfortunately that's not what I want.

When working with the built-in styles always use the enumeration. The code below will print the localized name of Heading 2 to the Immediate window.
Debug.Print ActiveDocument.Styles(wdStyleHeading2).NameLocal
https://msdn.microsoft.com/en-us/vba/word-vba/articles/wdbuiltinstyle-enumeration-word

Also, when your document is going international, and you are using chapter names in the header or footer, don't use
{ StyleRef "Heading 1" }
because when the document is shown in a German MS Word, it wouldn't understand "Heading" but expect "Überschrift" instead.
However, there's an international version, too. Just use
{ StyleRef 1 }
without quotes around the heading number.

You can't reference "Titre 2" as "Heading 2". Instead, see 'WdBuiltinStyle Enumeration'. Knowing these constants for the most part means you don't need to know the local names and, when you do, you can retrieve them via .NameLocal.
See also 'WdListNumberStyle Enumeration', 'WdCaptionNumberStyle Enumeration', 'WdNoteNumberStyle Enumeration', 'WdApplyQuickStyleSets Enumeration', and 'WdStyleType Enumeration' in the Word VBA help file.

Related

Creating custom snippets in VScode without having to wrap every single line of the snippet in quote marks

I have recently switched over from SublimeText. Overall its been good but am stumped and now frustrated with VScode approach to creating custom snippets.
"My Snippet": {
"prefix": "My Trigger",
"body": [
"Line 1",
"Line 2",
"Line 3",
"Line ...",
"Line 100"
],
"description": "My Description"
}
Like in the above exam, every line of my snippet has to be wrapped in " " and also , . This is so far from the WYSIWYG creation process, am to used in Sublime. Snippets are a big part of how I work and I cannot imagine having to do this for complex snippets that require inconsistent Tab spacing.
I spent the last two hours on trying to come up with a decent process for inserting " " and , after I finish writing my snippet using things like multi line editing but its highly unpredictable due to Tab spacing and sometimes needing to escape " " itself at time.
Surely there are ways around this?
Please I am not looking for GUI approaches to creating snippets,
I would like to create and edit my snippets via text editing. I am open to extensions that achieve this somehow though
I have taken the liberty to crosspost this question on other forums as well.
Any help would be greatly appreciated!

TMLanguage, what does captures do?

I am working on a tm language project for vscode and I'm wondering what the captures property on a pattern does exactly.
I can't seem to figure out what the indexes of the captures object stand for and I can't find any information on it online.
Example:
{
"match": "(group 1)(group2)"
"captures": {
"0": {
"name": "Name of first capture group? What does 0 mean here?"
}
}
}
The "captures" key is documented here, in the "Rule Keys" section (12.3):
https://macromates.com/manual/en/language_grammars
The name is not the name of the first capture group. It is just a string that specifies the name of the style to apply to the characters that were matched by that capture group. When I say "capture group", I am referring to a matching left paren and right paren in your regular expression.
Using the "captures" key is a relatively complex way to assign style names to characters in the document. It allows you to specify different styles to different portions of the text matched by the regular expression. A simpler way is to just use the "name" key, which will apply the style to all of the matched text.

Is there a way to add a blank option with VS Code snippets placeholder choices?

I am trying to create a snippet that gives me choices for optional attributes. I have used this approach in the past where I just put a blank space as a choice in the placeholder. That works when there is only one option between other parts of the snippet but like in the following example if I wanted to skip both placeholders (optional attributes on the adorn) there would be multiple spaces in the generated code which I would have to delete manually.
"Adorn":
"prefix": ["adorn"],
"body": [
"<%= adorn${1| , color: :blue, color: :white|}${2| , inline: true|} do |a| %>",
"\t$0",
"\t<%= a.adornment %>",
"\t\t",
"\t<% end %>",
"<% end %>"
],
"description": "An adorn"
},
From what I can see in the documentation it doesn't seem possible to do what I want using placeholders and choices. I thought I could use a variable and just have it resolve to empty string but the grammar doesn't seem to allow for that.
Is there any other way to accomplish what I am trying to do?
You can use some unicode characters in snippets, so I tried backspace (did not work) but \u200B which is a "zero-width space" does. So you can do this in your choices:
{1|\u200B, color: :blue, color: :white|}${2|\u200B, inline: true|}
and if you choose the blanks (i.e., the \u200B's) a zero-width space will be inserted. And you get what you want - no spaces to be deleted.
But I leave it to you to see if there are any parsing or other problems with having that character in your code. Maybe it is or isn't a problem in your language. See the open issue (which I found after posting this answer initially) https://github.com/microsoft/vscode/issues/34368 ("Allow "empty" as a choice in snippets
") where the zero-width space option is warned against and may cause problems - so test it. It doesn't look like there is any other option but a regular space which you have tried.
I tried "null" \u0000 and it wasn't recognized by vscode.
if a blank space is all you need, then all is needed is an '$1' that the placeholder.
but first let's see if you have errthing
First
at the root of yow project you need a new dir call .vscode
in side yow dir add a new file NOTE name is very important yow new file's must have this pattern any.code-snippets
in side yow new file add this
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
"Print to console": {
"scope": "javascript,typescript",
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
}
}
To finish I recommend you to remove the scope attribute. and do not use the file for more than one language, bcuz if you do so it may not work at all.
The best way to get an empty value for a placeholder with choices is to add a choice of 1 character and remove this with Delete or Backspace (depending where the cursor is, it differs for the 2 placeholders) and then TAB to the next placeholder.
To get the choice list for placeholder 2 press TAB when you are at placeholder 2.
Watch the location of the separating spaces, they are at the end of the choice.
"Adorn": {
"prefix": ["adorn"],
"body": [
"<%= adorn ${1|e,color: :blue ,color: :white |}${2|e,inline: true |}do |a| %>",
"\t$0",
"\t<%= a.adornment %>",
"\t\t",
"\t<% end %>",
"<% end %>"
],
"description": "An adorn"
}

Can I make different sections in Word, not only have the same header and footer, but page numbers that align as one whole document

Basically, I go to "Layout" > "Page Setup" > "Margins" > "Custom Margins" then selected the "Orientation" as "Landscape" then "Apply to:" > "This point forward", this changes the orientation of the pages for the rest of the document from where the blinking cursor sits, then I repeat the process with the cursor on the next page but choose the "Orientation" to "Portrait". This is how I make a specific page in a word document landscape. When this happens it sections that landscape page as "Section 2" and the pages after that "Section 3". The problem comes with the header and footer, in each section the header and footer is different. This is especially problematic with page numbers, as each new section starts as its own thing and says it is page one at the start of that section.
I have tried "Header & Footer" > "Navigation section" > "Link to previous" for "Section 2" to "Section 1", this would not display any information at all from "Section 1" to "Section 2". For some reason when I did the same for "Section 3" to "Section 2", "Section 3" would display the information of "Section 2", this does not solve the page numbering issue though because "Section 3" starts off as page 1. So it is weird to me how the "Link to previous" feature worked only on "Section 3" and not "Section 2".
If anyone has any method of fixing this I would be grateful :D, I will also be grateful for any dodgy ways of getting around it but I will not mark it as an answer.
I would add this as a comment but am new and not allowed to comment.
This would be better handled on the Microsoft Answers site as it about general Word features rather than programming.
That said, what happened was when you created a new section, likely before you did the orientation shift, you told Word to restart numbering at 1. Word took that as the way to start new sections. You can manually go to each new section and use the format page number dialog to tell word to continue from previous.
It sounds as if you may also have "different first page" set. This is a setting that continues into new sections as well. Header/footer settings with multiple sections and their interactions get complex. It is summarized here: Header/Footer Settings Recap.
You can download an Add-In from my site that will do this for you. Continuous Page Numbers Add-In. That uses a macro to do this.
Sub ContinuousPageNumbersMacro()
'
' ContinuousPageNumbersMacro Macro
' This macro makes page numbering continuous througout document. This is for multisection documents where it may be hard to find page breaks and figure out page numbering changes.
'
' Jay Freedman
' http://answers.microsoft.com/en-us/office/forum/office_2007-word/page-numbers-are-all-fouled-up-in-my-large/d188687e-9663-43e0-a450-1dbadc47f09f
' Can be used as straight macro or attached to keyboard shortcut
' modified to preserve track changes status - idea from Graham Mayor 25 Oct 2017
'
Dim secNum As Long
Dim btnCancel ' give user chance to cancel
Dim bTrackChanges As Boolean
Dim strVersion As String
strVersion = ThisDocument.CustomDocumentProperties("Version").Value
btnCancel = MsgBox(prompt:="Do you want to reset all of the page numbers in this document to number continuously?", _
Title:="Continuous Page Numbering Version " & strVersion & " Are you sure?", _
Buttons:=vbYesNo)
If btnCancel = vbNo Then
MsgBox prompt:="Reset of continuous page numbering cancelled by user!", Buttons:=vbExclamation, Title:="Page Number Reset Cancelled!"
Exit Sub
End If
' Proceed with reset
bTrackChanges = ActiveDocument.TrackRevisions 'Graham Mayor
ActiveDocument.TrackRevisions = False ' Graham Mayor
With ActiveDocument
For secNum = 2 To .Sections.Count
.Sections(secNum).Headers(wdHeaderFooterPrimary) _
.PageNumbers.RestartNumberingAtSection = False
Next
End With
ActiveDocument.TrackRevisions = bTrackChanges 'Graham Mayor
MsgBox prompt:="The Continuous Page Numbers macro has run.", Title:="Page number reset macro finished!"
End Sub

Is There a Way to do a Spanish/English MailMerge?

I have an SSRS report that has Spanish and English text boxes. If the dataset row is a Spanish speaking person, an expression in each Spanish textbox shows that and hides the English textbox. These textboxes are exactly placed over each other.
My boss wants me to use SSRS to generate an Excel spreadsheet from the dataset(this is not hard) and use Word template for a mail merge. However, I am having trouble trying to figure out if I can hide all English when row is a Spanish row and vice versa. These are health clients of Spanish and English nationality.
I can do mail merges attached to a Recordset, I can do one in English, one in Spanish. I am trying to avoid this and have it all in one Mail Merge.
Areas marked in red will change to Spanish translation and/or date format. The dates are a no-brainer I can use a conditional IIF, however the formatted body I have no solution for, based on value in Field "CL_Language" which is either "Spanish" or "English".
====================================
The merge fields for dates and greeting are easy. There is no merge field for the text. And yes, only option might be for 2 separate reports with different Recordsets.
It's not clear what the actual issue is but...
Instead of hiding textboxes, which could cause problems when exporting etc., why not set a single textbox to the correct language text using an expression?
Something along the lines of
=IIF(Fields!Language.Value = "English", Fields!MyEnglishText.Value, FieldsMySpanishText.Value)
I found a solution. But it could be very difficult for the client to create. It involves hitting Ctrl + F9 which will create curly brackets {}.
Inside those curly brackets an IF statement is placed and I just pasted the whole Spanish formatted body in the true area, and the whole English body in the false area.
{IF "CL_Language" = "Spanish" "spanish body text here" "english body text here"}
Very strange syntax and you need to right click on the area to see choices like "Toggle Field Codes" (IF statement get's hidden), "Edit Field", and "Update Field". With Edit Field and Update Field you get a popup with the fields in your recordset.
If you saw the examples in my question, you can see that is some big clunky text AND . . .inside of it is a merge field that works! The Excel recordset comes already with the month name in correct language for each row.
Since it is not smart to include links that might expire, I am including the Google text I used to find this solution. Then I took a chance on a huge formatted chunk of text with a merge field inside of it.
Google this: "If Merge Field then"
Now is this a viable solution for the client versus just having a Word template for each language?
I think this is too difficult and I even duck when running it. Also, once it's working, if I look at the toggled code, the Conditional field no longer says the field name, but the value in the field, go figure.
{IF "Spanish" = "Spanish" or {IF "English" = "Spanish" instead of {IF "CL_Language" = "Spanish" or {IF "CL_Language" = "English"
Here is how to access the fields using right click. (remember, your curly brackets HAVE to be created with Control + F9).