Object Variable or With block variable not set error

teachman

Active Member
Joined
Aug 31, 2011
Messages
310
Hello,

Using stream.WhiteLine in a VBA script is giving me the Object variable or With block variable not set error msgbox. Clicking on the Debug button brings me to the line that is written
stream.WriteLine " "

This is happening at the end of the script. But, I've used the stream.WriteLine probably about 100 times up until this point. I DIM fso As New FileSystemObject in the first ten lines of the script. Then I Dim stream AS TextStream. Then I Set stream = fso.CreateTextFile ("C:\temp\Tech Soil Service Error.log", True).

As I've said, I probably use the streamWriteline at least 100 times before I get the Object variable or With block variable not set error msgbox.

The script is writing the stream.WriteLine to the error log file.

I've used this same construct for years and never had this issue before. I'm using Excel 2016.

Thanks,

George Teachman
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,267
Office Version
2013
Platform
Windows
It is obviously losing its attributes somewhere between the last place it worked and where you are getting the error. You can either post that part of the code so we can look at it, or you can use the F8 function key and step through the code to see for yourself where the variable loses its value. If at some point you delete the object that the variable represents then the value reverts to 'Nothing'.
 

teachman

Active Member
Joined
Aug 31, 2011
Messages
310
It is obviously losing its attributes somewhere between the last place it worked and where you are getting the error. You can either post that part of the code so we can look at it, or you can use the F8 function key and step through the code to see for yourself where the variable loses its value. If at some point you delete the object that the variable represents then the value reverts to 'Nothing'.
MrExcel seems to have changed its way of replying to a thread answer or question. So, hopefully this will work. Buried deep in the code I found a stream.Close line after which there were other stream.WriteLine commands.

I found this by using the F8 'step by step' function.

JLGWhiz, thanks for the suggestion.

Thanks,

George Teachman
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,267
Office Version
2013
Platform
Windows
Glad you found the problem.

MrExcel seems to have changed its way of replying to a thread answer or question.
Not sure what this means, but the replies you get on the forum depends upon who responds and how they interpret the issue in the OP. All responders are volunteers who simply think they can help and some are more experienced than others, ranging from novice to professional. I have been a member of this forum for only about eight years but have not noticed any changes in in how replies are made.
 

teachman

Active Member
Joined
Aug 31, 2011
Messages
310
I think the problem is related to IE11. When I connect to Mr. Excel using IE over the Internet speed between me and the Mr. Excel server slows to a low baud speed. So slow that I have to physically slow down my typing. My problem may have just been another manifest station of the overall issue with IE. I tried changing to Firefox, but sometimes have the same throttled down response time. I've finally gone to Chrome.

Anyway, this group has been so helpful over the years, I really appreciate it. By the way, i'm suffering from the keyboard response time right now.

Thanks.
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,267
Office Version
2013
Platform
Windows
I was having a similar problem with IE and found that clicking the Internet Settings and Compatibility View I could enter the offending site into a dialog box and it cleared up the jumping and jerking.
 

teachman

Active Member
Joined
Aug 31, 2011
Messages
310
I'll give that a try the next time I need to ask you guys some questions. And, there WILL be a next time;)

Thanks,

George Teachman
 

Forum statistics

Threads
1,081,753
Messages
5,361,097
Members
400,613
Latest member
Markdc123

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top