Accidental use of built in function as variable name? - vba

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.

Related

Remove Attributes on Rubberduck VBA

I'm just getting into using Rubberduck for my VBA applications. I came across a great post on adding attributes here:
How to set the Attribute VB_PredeclaredId using RubberDuck '#PredeclaredID
However, what if I want to remove the attribute? It seems like the only way to do it is via code inspections. However, after you initially set the '#PredeclaredId, there's no longer any error that shows up. So the option to remove the attribute is no longer available.
I tried deleting the attribute, but the "Predeclared" annotation is still in my explorer:
I'm sure I can export, edit in the text editor, and then re-import again, but one purpose of rubberduck is to avoid doing that.
Thanks.
After deleting the attribute annotation there will be a new "attribute value out of sync" inspection with 2 options:
adjust attribute value
adjust annotation
You want to do the first option which will nuke the hidden attribute value.
Update
Another 2 alternatives:
indent the module ctrl+m
cut and paste the code ctrl-a ctrl-x ctrl-v
Both these options will wipe out the attribute values by forcing VBA to recompile the module without them. This is normally an annoyance (indenting my project wipes the attributes and I need to restore them with RD annotation inspections)
Final thing remember to refresh RD code explorer so it picks up the changes and the icon will change. This often happens automatically though.

How to move cursor to Vue methods, computeds, data quickly in VS Code?

I already tried using the symbol explorer in VSCode (CTRL+P then write #). It allows me to jump to data (because it's a method) but it won't jump to normal properties like "computed:" or "methods:"?
This would be useful when eg. I look at my component and think "Aha! I need to add a computed, so let's jump to computeds". I could just CTRL+F but this sometimes doesn't work if another variable or comment has 'computed' in its name
Currently, you can
use Ctrl+R to open Go To Symbol in Editor,
then enter some words like data, computed or methods and etc.,
then press Enter
The cursor would be moved to the selected symbol. Tested in Win10/v1.48.2
The easiest way how to do that is probably using Bookmarks extension.
I am using them and also I haven't find a better way how to solve same problem as you have.

Problem with intellij idea rename variable?

When I try to rename a variable using Shift + F6 or simply Refactor => Rename, sometimes intellij renames not only the one I want to, but also some other variables (in other files) with the same name and all their references which are completely irrelevant.
When I further studied that behavior I got to know that it happens only for public variables. Refer below screenshot. I tried to rename the squared variable (keywords). There are lots of totally irrelevant code lines are suggested below to rename accordingly.
Do some one know what the exact problem here? And a convenient solution?
Thank You.
Disable the option to search in comments and strings in the Rename dialog:
The option is available when you press Shift+F6 twice.

How to copy a word document section-by-section

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.

Set breakpoint in VBA code programmatically

I have a very large piece of code written in VBA (>50,000 lines - numerous modules). There is one array of interest to me, and I'd like to find all the conditions under which the value of any element of this array changes. The values can change in any module. Running the script line by line is not the most efficient option due to the size of the code.
I am looking for better ways to solve this problem. Two ways that come to my mind is to programmatically set a breakpoint (which I am not sure if can be done) or programmatically insert an if-block after each assignment that somehow alerts me that the value has changed. (not preferred).
So my question boils down to:
Is it possible to programmatically set breakpoints in VBA code?
If the answer to the above question is No, what is an efficient way to solve this problem?
UPDATE:
Thanks for the comments/replies. As I had implied, I am interested in the least amount of modification to the current code (i.e. inserting if-blocks, etc) and most interested in the break-point idea. I'd like to know if it's doable.
Use the keyword STOP to break te code if a certain condition is true.
There are Two Ways to do that:
Use Stop Key word. Example as given below, set a break point at Stop
if (x = 21 ) Then
Stop
End If
Using Add Watch
Go to Debug -> Select Add Watch
NB:I know this is an old topic but this could help others.
You could use Watches:
Right click on the variables you wish to monitor -> Add Watch...
In Watch Type: 'Break when value changes'
While you run your code, you can check the status of your Watches thanks to the Watch Window (accessible from the 'View' menu)
in the hope someone can benefit from this :
In such situations regardless of the programming language used - writing a few lines of code either in Perl, AWK or even shell scripts can solve the problem :
search for a regular expression containing the array name (ignoring case).
Once you export all modules and classes in the Workbook(s) into a given directory - the scripts can search those for you.