Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
|
Lista Forumurilor Pe Tematici
|
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login
POZE MRRRR'S FORUM (VIEW ONLY)
Nu sunteti logat.
|
Nou pe simpatie: Cezi
| Femeie 19 ani Vaslui cauta Barbat 23 - 80 ani |
|
TRaP
Moderator
Inregistrat: acum 6 ani
Postari: 787
|
|
Sources:
1st source provides a different approach than 2nd. I added my CustomRibbon.dotm file to be ignored and wdDoNotSaveChanges to close word documents without saving.
If I open multiple word documents at the same time (eg select 3 files, right click and Open) it will only show one instance in VBA, thus count only 1 document. This generates VBA errors and Normal.dotm errors.
If you are not willing to double click / select-enter on every word document that you want to open, you can easily open 1, then drag the next ones onto the title bar of an open document - it has to be on the title bar (on top).
You don't have to drag and drop documents 1 by 1 onto the title bar. After you open 1 word document, select all the rest then drag and drop them onto the title bar of the open document.
Sub CloseAllDocsExceptCurrentOne() Dim i As Integer Dim strKeepOpen As String strKeepOpen = ActiveDocument.Name
Dim customRib As String customRib = "CustomRibbon.dotm" For i = Documents.Count To 1 Step -1 If Documents(i).Name <> strKeepOpen And Documents(i).Name <> customRib Then Documents(i).Close savechanges:=wdSaveChanges 'add wdDoNotSaveChanges if you don't want to save them End If Next i
End Sub
|
Modificat de TRaP (acum 5 ani)
|
|
pus acum 5 ani |
|
TRaP
Moderator
Inregistrat: acum 6 ani
Postari: 787
|
|
2nd source offers 5 different approaches: - Method 1: Close All Open Documents except the Current One - Method 2: Close All Documents Opened after the Current One - Method 3: Close All Documents Opened before the Current One - Method 4: Close the Current Document together with All Documents Opened after It - Method 5: Close the Current Document together with All Documents Opened before It
Below is Method 1 from source 2:
Sub CloseAllDocsExceptCurrentOne() Dim objDoc As Document Dim objDocumentsToBeClosed As New Collection Dim nCount As Integer nCount = Application.Documents.Count For nIndex = 1 To nCount Set objDoc = Application.Documents.Item(nIndex) If objDoc.FullName <> ActiveDocument.FullName Then objDocumentsToBeClosed.Add objDoc Else Exit For End If Next nIndex For Each objDoc In objDocumentsToBeClosed objDoc.Close SaveChanges:=wdSaveChanges 'add wdDoNotSaveChanges if you don't want to save them Next objDoc End Sub
|
Modificat de TRaP (acum 5 ani)
|
|
pus acum 5 ani |
|