Object Variable or With block variable not set error

teachman

Active Member
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
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
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
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
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
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
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
 

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top