'Change the data file path for all files in a specific directory Sub Main 'Initialize Grapher Dim Grapher, PlotDoc, Plot As Object Set Grapher = CreateObject("Grapher.Application") Grapher.Visible = True '====================================== 'User-defined variables '====================================== Directory = "c:\temp\" file$ = Dir$(Directory + "*.grf") dataDir = Directory+"Data\" '====================================== 'Loop through all GRF files in the directory While file$ <> "" 'Open the file in the directory in order Set PlotDoc = Grapher.Documents.Open(Directory+file$) 'Loop through all objects in the file For i =1 To PlotDoc.Shapes.Count 'If the object is a Graph then count the number of plots in the Graph If PlotDoc.Shapes.Item(i).Type = grfShapeGraph Then 'Loop through all the plots in the graph to change the data file path For j=1 To PlotDoc.Shapes.Item(i).Plots.Count 'Store the existing file path and file name fulldata = PlotDoc.Shapes.Item(i).Plots.Item(j).worksheet path = Left(fulldata, Len(fulldata)-(Len(fulldata)-InStrRev(fulldata,"\"))) dataname = Right(fulldata, Len(fulldata)-(Len(path))) 'Change the file path PlotDoc.Shapes.Item(i).Plots.Item(j).worksheet = dataDir+dataname Next j End If Next i 'Save GRF as a new name filename = Left(file$, Len(file$)-(Len(file$)-InStrRev(file$,".")+1)) outfile = filename+"_newdatapath.grf" Debug.Print outfile PlotDoc.SaveAs(Directory+outfile) file$ = Dir$() Wend End Sub