0

I apologize for the question that seems to be quite simple but for which I haven't been able to find an answer online.

I am interested in retrieving variables' names and values that were used before Excel crashes.

According to Write contents of immediate window to a text file it is possible to write a log to a text file. According to reading and writing a csv file using FileSystemObject it is also possible to create a CSV file

Suppose that at one point myVariable = "Hello" and then later in the macro myVariable = "World"

My question is:

How can I format this log as a two column table where the first column would be the list of the names of the variables that have been specified (here myVariable) and the second column would only be the latest value of the variables in use (here "World"). The rows of the table would be incremented as new variables are defined and the second column of the table would be overwritten as the values of those variables change.

user1627466
  • 411
  • 5
  • 14
  • Apologies I meant creating a CSV file. It seems that it is possible according to https://stackoverflow.com/questions/9442215/reading-and-writing-a-csv-file-using-filesystemobject/9442846#9442846 What i can't figure out is how to ask Excel for a table of varName=varValue in a way that overwrites the rows of this table as the values evolve during the macro. – user1627466 Nov 20 '18 at 11:40
  • Excel does not do that. At each point in your program where you change a variable's value, you also put a `Print` statement. Tedious manual job, no magic. If is much simpler if you just dump each new value as its own line and then when you read the log later, you only respect the latest value. – GSerg Nov 21 '18 at 10:11
  • Thanks, this is counterintuitive. I would have thought Excel was aware of the changes made as one can see the value of a variable when one hovers above its name. – user1627466 Nov 21 '18 at 10:17

0 Answers0