Object Variable or With block variable not set error

teachman

Active Member
Joined
Aug 31, 2011
Messages
303
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,101
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
303
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,101
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
303
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,101
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
303
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,078,240
Messages
5,339,031
Members
399,274
Latest member
WilliamWavehill

Some videos you may like

This Week's Hot Topics

Top