Sub Main() Dim tmpFileName As String Dim tmpFileList, tmpFileIndex As Long tmpFileList = Application.GetOpenFilename("XY plot File(*.xls),*.xls", , "确定需要转换XY图方向的文件", , True) If VarType(tmpFileList) = vbBoolean Then Exit Sub Else Application.ScreenUpdating = False Application.StatusBar = "数据处理中,请稍等..." For tmpFileIndex = 1 To UBound(tmpFileList) Application.StatusBar = tmpFileIndex & "/" & UBound(tmpFileList) & "文件处理中..." tmpFileName = tmpFileList(tmpFileIndex) ChangeXYPlot tmpFileName Next tmpFileIndex End If Application.StatusBar = False End Sub Sub ChangeXYPlot(myFileName As String) Dim c As Chart Dim XYPlot As Series Dim tmpX As Variant, tmpY As Variant Dim ws As Worksheet Dim i As Long, j As Long Dim tmpBook As Workbook Set tmpBook = Application.Workbooks.Open(myFileName, , True) For Each ws In tmpBook.Worksheets For i = 1 To ws.ChartObjects.Count Set c = ws.ChartObjects(i).Chart For j = 1 To c.SeriesCollection.Count Set XYPlot = c.SeriesCollection(i) With XYPlot Select Case .ChartType Case xlXYScatter, xlXYScatterLines, xlXYScatterLinesNoMarkers, xlXYScatterSmooth, xlXYScatterSmoothNoMarkers tmpX = .XValues tmpY = .Values .XValues = tmpY .Values = tmpX End Select End With Next j Next i DoEvents Next ws tmpBook.Close False End Sub '----代码结束------- 使用方法: 1.随便建立一个新的工作表,按ALT+F11键进入VBA编辑状态 2.点菜单栏的“插入”,选“模块” 3.将以上代码复制,然后粘贴到空白处。如果需要可以按保存按钮进行保存。 4.按F5键执行宏,选择main执行 5.出现提示框,要求选择要执行X-Y方向转换的图所在的文件。(一次可以多选,但只限为一个目录下) 6.点“打开”按钮,然后开始自动转换,它会搜索工作簿内所有的图,看它是否为X-Y散点图类型,如果是则完成转换工作。直到所有文件都被执行。
[此贴子已经被作者于2007-3-28 0:30:07编辑过] |