Opening, Saving, and Closing Documents
The Documents collection provides access to the Surfer file commands. Use the Document object’s "Open" method to open an existing plot, worksheet, or grid file. Use the Add method to create a blank plot or worksheet. The SaveAll method saves all open documents, and the CloseAll method closes all open documents. To save or close an individual document, use the Document object’s Save, SaveAs, and Close methods.
Sub Main
Set SurferApp = CreateObject("Surfer.Application")
SurferApp.Visible = True
' Create a blank plot
SurferApp.Documents.Add srfDocPlot
' Create a blank worksheet
SurferApp.Documents.Add SurferAppDocWks
' Open an existing plot
filename$ = GetFilePath(,SRF)
if filename$ Then
SurferApp.Documents.Open filename$
End If
' Open the sheet named "Sheet1" from an Excel file
filename$ = GetFilePath(,XLS)
If filename$ Then
SurferApp.Documents.Open filename$, Sheet=Sheet1
End If
' Close the active document
SurferApp.ActiveDocument.Close
' Save the active document using its current name
If Not SurferApp.ActiveDocument.Saved Then
SurferApp.ActiveDocument.Save
End If
' Save the document whose window caption is "Plot1"
SurferApp.Documents("Plot1").SaveAs "MyDocument
' Close all documents
SurferApp.Documents.CloseAll
End Sub