VBA or script to close specific files

Discussion in 'AutoCAD' started by A.Design, Jun 11, 2004.

  1. A.Design

    A.Design Guest

    Hi,

    Is it possible to write a script or VBA to close specific files by pushing
    just a
    bottom ?let say I have 6 files open and wants to close 4 of them
    automatically by writing their name and location on the script file,Is this
    possible ?

    Any help would be appreciated.
     
    A.Design, Jun 11, 2004
    #1
  2. A.Design

    MarkusV Guest

    Hi,

    I just wrote a little VBA that will do this for you, you just have to link it to a button. What it doesn't do is take the full path of the file (only the file name) but it shouldn't be a big problem to use the full path and file name of the document you want to close.

    The doc.txt file contains:
    Drawing1.txt
    Drawing3.txt

    Code:
    
    Sub Close_Drawings()
    
    Dim doc As Object
    Dim closeDocuments() As String
    Dim i As Integer
    
    'filename and path to documents collection
    fileClose = "c:\temp\doc.txt"
    
    i = 0
    'reads all rows in file
    Open fileClose For Input As #1
    While Not EOF(1)
    ReDim Preserve closeDocuments(i)
    Input #1, closeDocuments(i)
    i = i + 1
    Wend
    Close #1
    
    'checks for open documents with the same name as the once in the file
    For n = 0 To UBound(closeDocuments)
    For Each doc In Application.Documents
    'if you want the full name to the document you could replace
    'doc.Name with
    'doc.Path & "\" & doc.Name
    'but remember to input the full path for the document in the text file
    If doc.Name = closeDocuments(n) Then
    'close document if found
    'WARNING! This does not save the document that is closed
    doc.Close
    End If
    Next
    Next
    
    End Sub
    
    
    Best Regards,
    Markus
     
    MarkusV, Jun 11, 2004
    #2
  3. A.Design

    A.Design Guest

    Thanks Markus.

    it to a button. What it doesn't do is take the full path of the file (only
    the file name) but it shouldn't be a big problem to use the full path and
    file name of the document you want to close.
     
    A.Design, Jun 11, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.