ERROR Open MyFile For Output As fnum

guybrown

Board Regular
Joined
Jul 2, 2008
Messages
100
Hi all!

I'm getting an error at Open MyFile For Output As fnum

I think there may be a problem with:
MyFile = ActiveWorkbook.Path & "\" & "Point_on_XY_" & Date & "_" & Time & ".scr"

Any ideas?

Sub WriteToATextFile()
'first set a string which contains the path to the file you want to create.
'this example creates one and stores it in the root directory
MyFile = ActiveWorkbook.Path & "\" & "Point_on_XY_" & Date & "_" & Time & ".scr"
'set and open file for output
fnum = FreeFile()
Open MyFile For Output As fnum
'write project info and then a blank line. Note the comma is required
'Write #fnum, "I wrote this"
'Write #fnum,
'use Print when you want the string without quotation marks
Print #fnum, A1
Close #fnum
End Sub
 
Maybe try eg:

Code:
MyFile = ActiveWorkbook.Path & "\" & "Point_on_XY_" & Format(Date, "ddmmyyyy") & "_" & Format(Time, "hhmmss") & ".scr"
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I figured it out! The Date and Time have semi-colons :::: in them and you can't have these in a file name! Took me a while! :)
 
Upvote 0
hehe and i've just seen that you worked it out before me Andrew!
Your method is better than mine... I took mid() & mid() & mid()... avoiding :
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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