Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete UnUsed Variables 1

Status
Not open for further replies.

srobiolle

IS-IT--Management
Mar 26, 2003
21
0
0
FR
Hi all,

Is there a way to quickly delete unused variables ? (those that appear with a red triangular icon at the beginning of the line) in Data/Variable (that is in a french version)

Thanks
Stéphane
 
Try this:

Data menu
Choose Variables
select the variables to don't need
Click on remove
 
Thanx, that's the way I do it today.
I'm looking for a "hidden" function which would do it automatically and delete all that is unused in a document.

Stéphane
 
Are you looking for one to actually delete them from the report or just to hide some items? I'm not sure I follow.
 
I often rearrange my reports to improve them, and I like to use variables. So, after a while, I get in my report a lot of variables that are not used anymore, because they are replaced by new ones (I keep the old ones in case).
To do so, I go and search every variable marked with a red icon to delete it and make some room in the report. That takes time...
 
I definitely understand. I do the same thing. Always a good idea to be able to go back to what you had if the new way isn't right.

I'm not sure if there is a clear unused variables function or something. I'll look around a bit.
 
You might be able to write something in VBA for this.

I know you can view all the variable values with something like this:

Code:
Dim var as Variable

For Each var In Application.Variables
     msgbox var.Name & ": " & var.Value
Next var

You can also use var.Delete This will not allow you to delete the built in variables, it might however allow you to delete one you created. I'm not sure.

Just hope this gives you an idea how to get around your problem. BTW, post it if you figure it out.
 
Hi DugzDMan,

Yes you are right but Application.Variables will give the System Level Variables of BO and one cannot Delete those. But instead we can use ActiveDocument.Variables and then do it. But as Steve said there is no function builtin so it will be bit tricky to find out all those red icon variables.

Sri
 
I tried that and the only variable it is recognizing is my prompt. Hhmm...

There has to be some way to do it, no one said it would be easy :)
 
Hi DugZDMan,

Its not ActiveDocument.Variables instead ActiveDocument.DocumentVariables to get hold off Document Variables. There will be some way. I'm in a hurry I will post a possible suggestion/workaround tomorrow.

Sri
 
Thanks Sri! I'll play with it for a bit and see what I get. No hurry from my side, I like being guided, then figure out some things on my own (besides, it's not even my thread :))
 
Thanks to all for your answers.
I've written a little script for which I would like your advice. It checks all variables and proposes to delete the ones that seems erroneous :

Sub CheckVariables()

Dim BadVariables As String
Dim Value As String
Dim Var As DocumentVariable
Dim VarEval As Variant

On Error GoTo ErrHandler

BadVariables = ""
For Each Var In ActiveDocument.DocumentVariables
If Var.Name <> &quot;&quot; Then
VarEval = ActiveDocument.Evaluate(&quot;=<&quot; & Var.Name & &quot;>&quot;, BoAllValues)
If IsEmpty(VarEval) Then
BadVariables = BadVariables & Var.Name & &quot; : undefined&quot; & Chr(13) & Chr(10)
If (MsgBox(&quot;Delete &quot; & Var.Name & &quot; ?&quot;, vbOKCancel, &quot;Undefined variables&quot;) = vbOK) Then
Var.Delete
End If
End If
End If
Next Var
If (BadVariables <> &quot;&quot;) Then MsgBox BadVariables
Exit Sub

ErrHandler:
BadVariables = BadVariables & Var.Name & &quot; : &quot; & Err.Description & Chr(13) & Chr(10)
Resume Next
End Sub

I've tested it on a few cases, it seems to work fine.

Stéphane
 
Hi,

Even I was thinking on those lines. Go thru the Variables and then do an Evaluate and based on the result do a delete.

Sri
 
Hi,

This thread is getting interesting....

Now when one creates a Variable if it is wrong then it cannot be created. Later when this Variable references another Variable it gets Bad/Wrong. But when do you say a Variable is Bad and Variable is Wrong.

Sri
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top