How to copy a word document section-by-section - vba

I have to update a word document to the most recent company template but that task is not so easy as it looks.
According to this site all it takes is to perform the described steps but after doing it the document remained as it was before, for instance, the footer and header remained the same, that is, they were not updated to the ones set in the new template.
After spending some time on how to accomplish that task I realized that both the header and footer are not related to the template but to the underlying section instead.
Then, I took another approach that boiled down to copy only the section content without the header and the footer to the already defined sections in the new template and apparently it gets the job done.
Therefore, I would like to know if there is any way to perform these section copying automatically - through VBA - or even other better approach I can take ?

Personally, I wouldn't use VBA unless the task was huge. By the time you've created some code, run it, failed, re-written it, you'll probably find that it could have been completed faster manually, especially if, as appears, this is a one-off job. Of course, if you encounter a task which you realise is repetitive and time-consuming, then you might make use of the Macro Recorder.
I obviously don't have the documents in front of me but:
Do a little planning. Work out how many sections there should be, and of what type (Next Page Section Break, etc.).
Use Draft View and Goto (Ctrl-G), Section to help discover them.
Scribble down an outline of what the final headers/ footers should contain.
If applicable, note down the Style names from both templates and work out which ones need to be replaced.
(I would) work on a copy of the new template and copy the content from the old one. This will copy the styles from the old template at the same time. This might be the wrong way round for you - you'll have to decide this. Try both and see which is easiest to work with.
You can use the Replace dialog (Ctrl-H) to swap one style for another.
Display the Styles Window as well (Ctrl-Alt-Shift-S).
From the Styles Window you can show the Style Manager. From here, and Import/Export, you can Delete, Rename and Copy Styles. Be careful about deleting styles as it is difficult to gauge what they will default to.
I would leave Headers and Footers until (second to) last and, when doing so, start at the beginning of the document and progress forward-only through the Sections, copying from the old template if necessary.
I would leave Bookmarks until the very end; by that time it should be easy to Insert them. If you have copied content from the old document then it should have carried the Bookmarks across as well, so it just a question of making sure that they are still in the right place.
Again, I don't have the templates in front of me, so I appreciate that some of this advice may not be relevant.
Hint: It might take a few attempts to get this right. If you get stuck at some point bear it mind that it might be better to start over - if it gets messy it is sometimes tricky to recover.

Related

How to undo in Intellij IDEA replace in files?

In intellij 2022.1, I use Ctrl+Shift+R to bring up the Replace in Files window - it shows 100+ matches in 40+ files. The search string and the replace string differ in only one character, for example: this.bar.is.fooed and this.barf.is.fooed. I only need to replace certain instances based on nearby text.
I'm in the groove, clicking the Replace button, checking the next entry, clicking, checking, ... and thinking my brain can keep things straight (it can't; neither can yours:-) I'm halfway through when I realize the last few replaces were wrong.
How can I undo them? Ctrl+Z is grayed out. This related SO question doesn't say and neither does the JetBrains documentation!
Use Local History to revert the changes.
Undo/redo is not supported for Replace dialog, vote for the related request.

Hide\remove language from VB.Net form list

Is there a way to make the language property list shorter? Make it show only EN-US and PT-BR, for instance, so it's easier to find them?
You probably don't need to do it.. You can likely just make your life easier like:
Make a new form, lets say it's called LocalForm.vb
Drop a label on it, lets say called HelloLabel
Set form to de-DE, set the text of the label to Hallo
Set form to fr-FR, set the text of the label to Salut
Set the form back to (default) - you now have LocalForm.resx, LocalForm.de-DE.resx and LocalForm.fr-FR.resx and you can add controls
Add a Button, called StartButton
Double click the LocalForm.de-DE.resx file
Dismiss the "if you mess this up you'll have to fix it yourself" dialog
Add a line for StartButton.Text Starten
Repeat for other language files
Dropping a control named XyzButton on the form, and then visiting each LocalFor.*.resx in turn and adding the locale for it is a lot easier than back-and-forthing with the language setting, though I know why it's done the way MS chose to do it - you're supposed to lay your form out perfectly with all its hundreds of controls, and then switch to French and write all the French for all hundreds controls, and then switch to German and write it all in German.. In a use case like that there isn't a lot of work to do with that awkwardly huge Language dropdown. Incremental adds that way are a bit of a pain..
Perhaps raise a connect bug/feature asking them to put the "already used" languages (as determined by the presence of Form.*.resx files) at the top of the list, and wait many years for it to be implemented :)
Note: There's a bit of a nuisance with this "edit the resx" in that if you rename a control it doesn't always get picked up. Last time I was localizing I threw together an app that watched (FileSystemWatcher) files named *Form.resx and if it saw a change (load the current version, compare to the prev version) that was a rename, it made the same change in the other files (or maybe alerted if they weren't in sync.. can't quite remember now and I've no idea where the code has gone)
Maybe don't rename your controls after you first decide a sensible name for them/add them to the translated resx..

How to save a folded code structure after file close

How can I save folded code structure after file close? It get me a lot of headache to fold a lot of code again each time when I reopen file.
You cannot save the particular state of the code folds as far as I know, but you can collapse certain code regions by default as shown here in the preferences.
What I do is use //region and //endregion for my custom folding code I want collapsed, and use documentation for things I want always seen (like explaining what is inside the code folds' logic where necessary).

Accidental use of built in function as variable name?

I have been writing some VBA code to produce charts automatically, and at one point named a variable "CHARTTITLE" not realizing that this is a member of the Chart object. I have deleted this variable upon realizing my mistake. However, since doing so, wherever I employ something like
Charts(1).ChartTitle.Text =
It will automatically auto-capitalize to
Charts(1).CHARTTITLE.Text
I have tried search and replace over the entire project from .CHARTTITLE to .ChartTitle to no avail. I have also tried employing Option Explicit also without effect. I am worried that there is now some sort of memory issue or that I've overwritten something important. Is there any way to reset this back to its default state?
It's a benign effect and it's a long-standing bug relating to the way that VBA stores itself internally. A couple of things to try:
Change the first occurrence of CHARTTITLE in the module, or if in multiple modules in the first module that appears in the project explorer.
Export the module, remove it from the project, edit it using your favourite text editor and reimport it.

Saving a position while coding?

Back in olden times, I used to code with an editor that allowed you to mark where you were in the code with a keypress. You could jump to another point in the same or another file to check a reference or somesuch. When you were ready, you could hit another keypress and return to the point you saved.
I've long since migrated to Dreamweaver and wanted this functionality. Does it exist in DW? If so, I missed that part of the manual. If not, any suggestions on an editor that DOES have that functionality?
Scott.
There is no official way to do it, but you could use the code collapse feature to create something like a bookmark. Collapse the single line and DW will have a mark at that line number until you clear it.