Option Explicit
' Load Libraries
Private Sub Command1_Click()
Dim a As New InDesign.Application
Dim d As InDesign.Document
Dim md As InDesign.MetadataPreference
Dim sar() As String
Dim s As String
Dim i As Long
On Error GoTo ErrHandler:
If a.Documents.Count > 0 Then
Set d = a.ActiveDocument
Set md = d.MetadataPreferences
s = Trim(md.Description)
If Len(s) > 0 Then
If InStr(1, s, ">") > 0 Then
sar = Split(s, ">")
For i = 0 To UBound(sar)
s = sar(i)
If Len(s) > 0 Then
a.Open s
End If
Next
Else
MsgBox "No one library was associated with " & d.Name
End If
Else
MsgBox "No one library was associated with " & d.Name
End If
Else
MsgBox "There must be at least one open document.", vbExclamation
End If
Exit Sub
ErrHandler:
MsgBox Err.Description, vbCritical
End Sub
' Save Libraries
Private Sub Command2_Click()
Dim a As New InDesign.Application
Dim d As InDesign.Document
Dim md As InDesign.MetadataPreference
Dim lb As InDesign.Library
Dim s As String
If a.Documents.Count > 0 Then
Set d = a.ActiveDocument
Set md = d.MetadataPreferences
If a.Libraries.Count > 0 Then
For Each lb In a.Libraries
s = s & lb.FullName & ">"
Next
md.Description = s
Else
MsgBox "There must be at least one open library.", vbExclamation
End If
Else
MsgBox "There must be at least one open document.", vbExclamation
End If
End Sub
Option Explicit
Private Sub Command1_Click()
Dim fso As New FileSystemObject
Dim ft As TextStream
Dim a As New InDesign.Application
Dim d As InDesign.Document
Dim sar() As String
Dim s As String
Dim f As String
Dim i As Long
On Error GoTo ErrHandler:
If a.Documents.Count > 0 Then
Set d = a.ActiveDocument
If d.Saved Then
f = Replace(d.FullName, "indd", "ini")
Else
MsgBox "Before save document: " & d.Name, vbInformation
Exit Sub
End If
If fso.FileExists(f) Then
Set ft = fso.OpenTextFile(f, ForReading)
s = ft.ReadAll
ft.Close
Else
MsgBox "Unable to open file " & f
Exit Sub
End If
If Len(s) > 0 Then
If InStr(1, s, ">") > 0 Then
sar = Split(s, ">")
For i = 0 To UBound(sar)
s = sar(i)
If Len(s) > 0 Then
a.Open s
End If
Next
Else
MsgBox "Invalid data", vbCritical
End If
Else
MsgBox "Invalid data", vbCritical
End If
Else
MsgBox "There must be at least one open document.", vbExclamation
End If
Exit Sub
ErrHandler:
MsgBox Err.Description, vbCritical
End Sub
Private Sub Command2_Click()
Dim fso As New FileSystemObject
Dim ft As TextStream
Dim a As New InDesign.Application
Dim d As InDesign.Document
Dim lb As InDesign.Library
Dim f As String
Dim s As String
If a.Documents.Count > 0 Then
Set d = a.ActiveDocument
If a.Libraries.Count > 0 Then
If d.Saved Then
For Each lb In a.Libraries
s = s & lb.FullName & ">"
Next
f = Replace(d.FullName, "indd", "ini")
Set ft = fso.CreateTextFile(f, True)
ft.Write s
ft.Close
Else
MsgBox "Before save document: " & d.Name, vbInformation
End If
Else
MsgBox "There must be at least one open library.", vbExclamation
End If
Else
MsgBox "There must be at least one open document.", vbExclamation
End If
End Sub