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
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I just tried putting ActiveWorkbook.Path in quotation marks and with and without the following \ but still the same error. I appreciate your help... frustrating...
 
Upvote 0
Have you tried:

Code:
MyFile =  "H:\AutoCAD\Scripts\" & "Point_on_XY_" & Date & "_" & Time & ".scr"
 
Upvote 0
i haven't but i'd like it to open/create the file in the same folder as the excel file if the excel file is moved hence the desire for activeworkbook.path
i'll try your suggestion though and see if it helps me to figure it out...
 
Upvote 0

Forum statistics

Threads
1,224,271
Messages
6,177,619
Members
452,786
Latest member
k3calloway

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