Consulting

Results 1 to 5 of 5

Thread: Close Open Text File - No Save Prompts

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    Close Open Text File - No Save Prompts

    Good Morning,


    how may i close an open text file on my desktop


    
    Sub Close_File()
    
    
    Dim FilePath As String
    
    'File Path of Text File
    
      FilePath = "C:\Users\DJ\Desktop\LA122.txt"
    
    
      'FilePath.Close
      
      Close #1
    
    End Sub

    I dont need to open it - I just want to close the already open file without any prompts or anything to save
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Assuming it is open in the same instance of Excel
        FilePath = "LA122.txt"
        Workbooks(FilePath).Close False
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Hello M,

    excel created the file initially.

    now later i just want to close it - because i dont want it anymore

    ok let me do some investiagtion
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  5. #5
    VBAX Newbie
    Joined
    Dec 2017
    Posts
    1
    Location
    NOT WORK THIS CODE,......................

Posting Permissions

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