Consulting

Results 1 to 3 of 3

Thread: Cannot open file (Error 53) for writing

  1. #1

    Cannot open file (Error 53) for writing

    Hello all!

    Hopefully I'm posting this question in the correct forum. I've done a search and I can't seem to find another post with the same problem I'm having, so here goes..

    I have a spreadsheet that writes out its contents to a comma delimited text file with some other info (header, footer, tokens, etc.), which I then use for parsing and loading into a database. This spreadsheet has always worked, but I haven't used it for months. All of the sudden I'm getting the "Cannot open file" error from the code below. I'm using Windows XP SP2 and Office XP. Previously I had been using this on Windows XP SP1 with Office 2000. Is there a security feature in either of the new products that's blocking the creation of the file?

    Sub CreateSIF()
    Dim DestFile As String
    Dim FileNum As Integer
    Dim strDate As String
    Dim strPath As String
    Dim ColumnCount As Integer
    Dim RowCount As Integer
    Dim LastRow As Long
    Dim LastCol As Long
    ' Get the date and path values from the spreadsheet
    strDate = Range("DateValue").Value
    strPath = Range("PathValue").Value
    ' Build the filename from the path and the sheet name
    DestFile = strPath & "\" & ActiveSheet.Name & "-" & strDate & ".dat"
    ' Get the next available file number
    FileNum = FreeFile()
    ' Turn error checking off
    On Error Resume Next
    ' Attempt to open destination file for output
    Open DestFile For Output As #FileNum
    ' If an error occurs report it and end
    If Err <> 0 Then
    MsgBox "Cannot open file " & DestFile
    End
    End If
    ' Turn error checking on
    On Error GoTo 0
     
    < Remainder of code >
    As I mentioned, this has always worked. It doesn't matter what I put in the path, even hardcoding "C:" doesnt work. The error message that comes up has the path and filename properly formatted, as well.. The file just won't open!

    Also, I have my macro security set to Low in Excel.

    Thanks in advance all,

    - Sam
    Last edited by samuel_77; 09-23-2005 at 09:06 AM. Reason: solved own problem

  2. #2
    Well, I'm a dummy. It was my anti-virus program (Kaspersky) blocking access to the script for disk I/O.

    No sooner had I finished posting this question that it dawned on me that I had that $!@# program running in the background. Sure enough, the advanced settings revealed it as the culprit.

    Thanks anyway forum folks, I'm sure I'll be back with a real problem soon enough...

  3. #3
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    Hi samuel_77, mark this thread as solved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •