Sub Main 'Initializes Surfer Dim SurferApp, Wks, WksRange, WksRange2, WksRangeN, WksRange3 As Object Set SurferApp = CreateObject("Surfer.Application") SurferApp.Visible = True '================================================================ ' USER DEFINED VARIABLES '================================================================ file_extension = "bln" 'extension of the data files in the directory in_dir = "C:\temp\OldBLNs\" 'directory containing all of the original BLN files out_dir = "C:\temp\NewBLNs\" 'directory containing the output BLN file '================================================================ 'If you didn't include a \ at the end of the file_directory, this line adds it If Len(in_dir)-InStrRev(in_dir,"\") <> 0 Then in_dir = in_dir + "\" If Len(out_dir)-InStrRev(out_dir,"\") <> 0 Then out_dir = out_dir + "\" 'This sets the file name equal to any BLN files in the directory orig_bln = Dir( in_dir + "*." + file_extension) 'Loops through all of the BLN files in the directory While orig_bln <> "" 'Open BLN Set Wks = SurferApp.Documents.Open(in_dir+orig_bln) 'Delete header row Wks.Rows(1).Delete(Direction:=0) Set WksRange2 = Wks.Columns(Col1:=1, Col2:=3) 'Duplicate each row For i = 2 To (WksRange2.RowCount*3-2) Step 3 Set WksRangeN = Wks.Rows(Row1:=i, Row2:=i) Wks.Range(Row:=i-1, Col:=1, LastRow:=i-1, LastCol:=3).Copy WksRangeN.Insert(Direction:=wksInsertDown) WksRangeN.Insert(Direction:=wksInsertDown) Wks.Range(Row:=i+1, Col:=1, LastRow:=i+1, LastCol:=3).Paste(False) 'Clear first row and instead enter col A value is 2, col B value is 0, and col C value is 'porosity, where porosity is the col C value for row # WksRange2.Cells(Row:=i, Col:=1).Value = 2 WksRange2.Cells(Row:=i, Col:=2).Value = 0 WksRange2.Cells(Row:=i, Col:=3).Value = "'"+WksRange2.Cells(Row:=i-1, Col:=3).Value Next 'Delete duplicate header row Wks.Rows(1).Delete(Direction:=0) 'Save the new BLN new_bln = out_dir + Left(orig_bln, Len(orig_bln)-(Len(orig_bln)-InStrRev(orig_bln,".")+1) ) + "_edited."+file_extension Debug.Print new_bln Wks.SaveAs(FileName:=new_bln, FileFormat:=14) 'Go to the next BLN file orig_bln = Dir() Wend End Sub