Public Sub SaveXMLString(fileName As String)
Dim FreeF As Integer, sFile As String, sLayout As String Dim XMLLayout As String
On Error Resume Next:
'Creates a string containing the CommandBars layout, state, and settings. The state options stored in the myStateOptions 'object specifies which settings should be saved to the string. To allow the XML file to be opened in the Designer Studio, 'the profile name MUST be set to "DesignerFile" XMLLayout = CommandBars.SaveStateToXMLString("DesignerFile", myStateOptions) 'XML string will be saved to a xml file. Note that the file extension is .XML. Opening a file 'of type XML in a web browser will correctly format the XML sting. sFile = fileName FreeF = FreeFile Kill sFile Open sFile For Binary As #FreeF Put #FreeF, , XMLLayout Close #FreeF End Sub
Public Sub LoadXMLString(fileName As String)
Dim FreeF As Integer, sFile As String, sLayout As String Dim XMLLayout As String
On Error Resume Next: 'XML string will be loaded from the file. sFile = fileName FreeF = FreeFile XMLLayout = Space(FileLen(sFile)) Open sFile For Binary As #FreeF Get #FreeF, , XMLLayout Close #FreeF On Error GoTo 0 If (Not bSaveOnlyCustomized And bSerializeControls) Then 'This is needed when the entire toolbar layout is loaded, not just user customization. 'When the layout is loaded, the toolbars not present in the saved layout will not be deleted. 'So you must manually remove all toolbars before loading a layout. 'NOTE: The XML file must have been saved with bSaveOnlyCustomized = False And bSerializeControls = True 'or the layout will not load properly. CommandBars.DeleteAll End If
'Load the "DesignerFile" profile from the myXMLLayout string. The state options stored in the 'myStateOptions object specify how and what to restore of the Command Bars settings. CommandBars.LoadStateFromXMLString "DesignerFile", XMLLayout, myStateOptions End Sub
Private Sub xmlFileLoad() Dim sFile As String
With dlgCommonDialog .InitDir = App.Path .DialogTitle = "Load XML Layout" .CancelError = False 'ToDo: set the flags and attributes of the common dialog control .Filter = "xml Files (*.xml)|*.xml" .ShowOpen If Len(.fileName) = 0 Then Exit Sub End If sFile = .fileName End With LoadXMLString (sFile) End Sub
Private Sub xmlFileSave() Dim sFile As String With dlgCommonDialog .InitDir = App.Path .DialogTitle = "Save XML Layout" .CancelError = False 'ToDo: set the flags and attributes of the common dialog control .Filter = "xml Files (*.xml)|*.xml" .ShowSave If Len(.fileName) = 0 Then Exit Sub End If sFile = .fileName End With SaveXMLString (sFile)
End Sub
|