Troubles with "OPEN FILE_NAME FOR APPEND AS #1"

rbaron

New Member
Joined
Nov 18, 2016
Messages
6
Hi all.

Totally new to this forum, as I have a perplexing problem that Google just isn't solving for me.

At work, we have upgraded to some new version of MS Office, using VBA 7.1
I am trying to append text to a text file, qwhich woirks fine as long as I don't specify any file location.

As soon as I specify a file location such as "C:/", I get runtime errors.My current code works, and saves the file automatically in the "C:\Users\baror1\Documents" (where baror1 is my userID when I log into Windows):

Private Sub Command427_Click()
Open "7705-LOG.txt" For Append As #1
Print #1, Me.CircuitID
Print #1, Me.NE1String
Print #1, Me.NE2String
Close
End Sub

The code above works just fine, and appends the text in the specified fields, into a text file na,ed "7705-LOG.txt", and places it automatically in the folder I've listed above.

The problem is, other users need to use the log file too, so I don't want it saving to my personal folder, I'd rather just save it to a network drive, or just the C: drive.

I have tried the following, but I keep getting the error I mentioned above:

ATTEMPT 1:

Private Sub Command427_Click()
Dim File_Path As String
File_Path = " C:\7705-LOG.txt"

Open File_Path For Append As #1

Print #1, Me.CircuitID
Print #1,
Print #1, Me.NE1String
Print #1, Me.NE2String
End Sub


The code above produces the following error:
Run-time error '52':
Bad file name or number


My next attempt looks like this:

ATTEMPT 2:
Private Sub Command427_Click()
Open "C:/7705-LOG.txt" For Append As #1
Print #1, Me.CircuitID
Print #1, Me.NE1String
Print #1, Me.NE2String
Close
End Sub

The code above produces the following error:
Run-time error '75':
Path/file access error





I can guarantee there's no problems accessing the C drive, and there's nothing wrong with the file name, as it works just fine when I don't specify a path.
Can someone please help!!??

All the code I've looked up online says this should work... why doesn't it?
 
you should use the Freefile function to get the file number instead of using 1

and yeah, don't assume you can write to C:\
I can't at work,
can't even use notepad to save a text file there
funny thing is I CAN create folder in C:\ and save a text file in it

your pc probably has a user named public
if you want more than one user to be able to see the file then you should probably save it to
C:\Users\Public\Documents\
 
Last edited:
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,221,783
Messages
6,161,940
Members
451,730
Latest member
BudgetGirl

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