Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time Error '5' - Invalid procedure call or argument Trefor Excel Discussion (Misc queries) 2 December 17th 07 03:32 AM
Invalid Procedure Call or Argument - Run-time error '5' Andrew Excel Programming 0 November 20th 07 09:03 PM
Run-time error '5': Invalid Procedure Call or Argument Nikila Excel Discussion (Misc queries) 2 February 24th 06 09:26 PM
Run Time Error 5 - Invalid Procedure Call or Argument Q John[_110_] Excel Programming 3 September 26th 05 09:47 PM
Run-time error '5':Invalid Procedure call or argument Jan Refsdal Excel Programming 1 July 25th 03 05:14 AM


All times are GMT +1. The time now is 12:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"