Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Invalid procedure call or argument for Dir$ (Run-time error '5') ?
I am getting a VBA error, "Run-time error '5': Invalid procedure
call or argument", at some point when I execute the "s = Dir$" command in the Sub FixCreateAndPrintAllCharts() code below, after it processes a lot of files. What might cause a Dir$ command to produce that error? Thanks, Alan Sub FixCreateAndPrintAllCharts() ' ' ' Dim StartDir As String StartDir = ThisWorkbook.Path ' MsgBox ("Start Directory: " & StartDir) Dim s As String Dim currdir As String Dim dirlist As New Collection If Right$(StartDir, 1) < "\" Then StartDir = StartDir & "\" dirlist.Add StartDir While dirlist.Count ' remove current directory from directory list currdir = dirlist.Item(1) dirlist.Remove 1 'find all files and subdirectories in current directory, and add them to list s = Dir$(currdir, vbDirectory) While Len(s) If (s < ".") And (s < "..") Then 'get rid of parent and current directory If GetAttr(currdir & s) = vbDirectory Then 'add the subdirectory dirlist.Add currdir & s & "\" Else 'process the file if it is right name If (s Like "FIXED_PerfWiz?*.csv") Then Workbooks.Open (currdir & "\" & s) FixAndCreateCharts ' PrintWPMcharts ' delete any existing data chart file ChartsFileName = currdir & "\" & "Data_Charts_FIXED_*.xls" If (Dir(ChartsFileName) "") Then Kill (ChartsFileName) End If ' save the workbook LResult = Replace(ActiveWorkbook.FullName, "FIXED_", "Data_Charts_FIXED_") LResult = Replace(LResult, ".csv", ".xls") ActiveWorkbook.SaveAs Filename:=LResult _ , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False ActiveWorkbook.Close End If End If End If s = Dir$ Wend Wend End Sub Sub FixAndCreateCharts() ' ' FixAndCreateCharts Macro ' Macro created 7/20/2008 by james.a.thomas ' ' ActiveCell.Columns("A:G").EntireColumn.Select Selection.ColumnWidth = 17.71 ActiveCell.Rows("1:1").EntireRow.Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Font.Bold = True Call CreateWPMchart("A:A,B:B,D:D,F:F", "Memory Utilization", "Page File Bytes") Call CreateWPMchart("A:A,C:C,E:E,G:G", "CPU Utilization", "% Processor Time") End Sub Sub CreateWPMchart(ColumnRange As String, ChartName As String, yAxisTitle As String) ' ' Create a WPM chart ' Charts.Add ActiveChart.ChartType = xlLineMarkers ActiveChart.SetSourceData Source:=Sheets("FIXED_PerfWiz - 5 second interv"). _ Range(ColumnRange), PlotBy:=xlColumns ActiveChart.Location Whe=xlLocationAsNewSheet, Name:=ChartName With ActiveChart .HasTitle = True .ChartTitle.Characters.Text = ChartName .Axes(xlCategory, xlPrimary).HasTitle = True .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = _ "Time (5 sec. intervals)" .Axes(xlValue, xlPrimary).HasTitle = True .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = yAxisTitle End With With ActiveChart.Axes(xlCategory) .HasMajorGridlines = False .HasMinorGridlines = False End With With ActiveChart.Axes(xlValue) .HasMajorGridlines = True .HasMinorGridlines = False End With ActiveChart.HasDataTable = False ActiveChart.ChartArea.Select ActiveChart.SeriesCollection(3).Select With Selection.Border .ColorIndex = 10 .Weight = xlThin .LineStyle = xlContinuous End With With Selection .MarkerBackgroundColorIndex = 10 .MarkerForegroundColorIndex = 10 .MarkerStyle = xlTriangle .Smooth = False .MarkerSize = 5 .Shadow = False End With ActiveChart.ChartArea.Select ActiveChart.SeriesCollection(2).Select With Selection.Border .ColorIndex = 9 .Weight = xlThin .LineStyle = xlContinuous End With With Selection .MarkerBackgroundColorIndex = 9 .MarkerForegroundColorIndex = 9 .MarkerStyle = xlSquare .Smooth = False .MarkerSize = 5 .Shadow = False End With End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Run-time Error '5' - Invalid procedure call or argument | Excel Discussion (Misc queries) | |||
Invalid Procedure Call or Argument - Run-time error '5' | Excel Programming | |||
Run-time error '5': Invalid Procedure Call or Argument | Excel Discussion (Misc queries) | |||
Run Time Error 5 - Invalid Procedure Call or Argument Q | Excel Programming | |||
Run-time error '5':Invalid Procedure call or argument | Excel Programming |