Open "MyFile.txt" for output as #1 creates an exe-extension!

Jorgen

Board Regular
Joined
Mar 25, 2004
Messages
67
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Hi
I have a workbook that is supposed to produce text-files and it has been working perfectly in a bunch of different computers until my colleague got a new Dell with XP and Office 2007.
The essential part of the macro is:

Sub Test()
Open “MyFile.txt” For Output as #1
---
Close 1
End Sub

Suddenly, on this computer only, the line creates the file "MyFile.EXE" and it doesn't make a difference what extension I have between the " ", it still ends up being an EXE.

Reinstalling the Office 2007 didn't help. neither does deleting the #

Has anyone else experienced this? Or has a good guess of the reason or solution?

Thanks
//Jörgen
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I had a similar issue with 2003 vs 2007.
I saved an excel sheet as a separate workbook using macros.
I found that I had to dictate to excel 2007 what file type I wanted to save as, otherwise it saves it in the wrong format.

I am not sure its the same issue but it sounds related.
Here is a link to where another person resolved the issue.

http://www.mrexcel.com/forum/showthread.php?t=504233&highlight=2003+2007+save+file+types

Good Luck!
 
Upvote 0
Sub Test()
Open “MyFile.txt” For Output as #1
---
Close 1
End Sub

The quotes look odd in your code - maybe that's just formatting in the post. Otherwise, seems very odd and possibly unexplainable, though I would post the rest of the code to be sure.

You might like to just use the FileSystemObject - I find it very reliable and use it all the time instead of the original VB6 file I/O functions (they are reliable too - generally speaking). You just create a text stream object which corresponds to a file. It has a lot of other useful features and is worth getting to know:
http://msdn.microsoft.com/en-us/library/aa155438(v=office.10).aspx
http://www.aivosto.com/visdev/fso.html

Note that at first you will want to set a reference to the Microsoft Scripting Runtime library in the VBE under tools references. This will give you intellisense for writing the code.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,290
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top