'GridSpacing.bas creates a GRD file with user defined grid spacing. Sub Main Debug.Print "----- ";Time;" -----" On Error GoTo createnew Set SurferApp = GetObject(, "Surfer.Application") On Error GoTo 0 GoTo skipnew createnew: Set SurferApp = CreateObject("Surfer.Application") SurferApp.Visible = True skipnew: 'Specifies the data file to grid path1 = SurferApp.Path+"\samples\" infile1 = GetFilePath(path1+"demogrid.dat","dat;csv;xls",path1,"Input Data File",0) Debug.Print infile1 'Specifies where to save the GRD file outfile1 = GetFilePath(,"grd",SurferApp.Path+"\samples\","Outfile",2) Debug.Print outfile1 'Specify the grid spacing you want gridspacing = InputBox("Enter Grid Spacing","Grid Spacing") Debug.Print gridspacing Set Wks = SurferApp.Documents.Open(infile1) Set WksRange = Wks.Columns(Col1:=1, Col2:=2) Set WksStatistics = WksRange.Statistics 'Calculates the min/max for the X and Y columns xmin=WksStatistics.Minimum(1) xmax=WksStatistics.Maximum(1) ymin=WksStatistics.Minimum(2) ymax=WksStatistics.Maximum(2) wks.Close Debug.Print xmin;xmax;ymin;ymax 'Calculate number of columns and rows from desired spacing. ncol=1+(xmax-xmin)/gridspacing nrow=1+(ymax-ymin)/gridspacing 'Creates a plot document window Set Plot = SurferApp.Documents.Add 'Grids the data SurferApp.GridData(infile1, NumCols:=ncol, NumRows:=nrow, Outgrid:=outfile1) 'Creates a contour map Plot.Shapes.AddContourMap(outfile1) End Sub