Hi all,
When I step-through my code below, it always opens the first file in the directory "C:\Pyramid Files", but when it comes back to the Pyramid Files sub after fully processing the first file via various other subs, the VB Editor apparently doesn't like something about this line: StrFile = Dir(), since it quits after "snapping-back" to the previous sub Initialize(). I have also tried StrFile = Dir, but that doesn't work either. I did Dim Strfile in the General Declarations. When I set Watches for Dir and Dir(), I get the value "Invalid procedure call or argument" for both, as if the directory function lost the value. I can't determine why this is happening. Can you see what I am missing?
When I step-through my code below, it always opens the first file in the directory "C:\Pyramid Files", but when it comes back to the Pyramid Files sub after fully processing the first file via various other subs, the VB Editor apparently doesn't like something about this line: StrFile = Dir(), since it quits after "snapping-back" to the previous sub Initialize(). I have also tried StrFile = Dir, but that doesn't work either. I did Dim Strfile in the General Declarations. When I set Watches for Dir and Dir(), I get the value "Invalid procedure call or argument" for both, as if the directory function lost the value. I can't determine why this is happening. Can you see what I am missing?
Code:
Dim WSM As Worksheet, WSB As Worksheet, WS1 As Worksheet, [U]StrFile As String[/U], StrDirectory As String, ClientCode As String
Dim Filename As String, LastRowb As Long, LastColB As Integer, LastRow1 As Integer, NextRowC As Integer, x As Integer, y As Integer
Public Sub Initialize()
Set WSM = ThisWorkbook.Worksheets("Macro")
Set WS1 = ThisWorkbook.Worksheets("Sheet1")
'Create a directory to store individual client files
On Error Resume Next
MkDir "c:\Client Code Files"
Application.ScreenUpdating = False
PyramidFiles
Application.ScreenUpdating = True
End Sub
Sub PyramidFiles()
StrDirectory = "C:\Pyramid Files"
StrFile = Dir("C:\Pyramid Files\HPES_Asset_Recon*")
Dim sh As Worksheet, flg As Boolean
Do While StrFile <> ""
For Each sh In Worksheets
If sh.Name = "Pyramid File" Then flg = True: Exit For
Next
If flg = True Then
WSB.Delete
Filename = StrDirectory + "\" + StrFile
OpenPyramidFiles
Else: Filename = StrDirectory + "\" + StrFile
OpenPyramidFiles
End If
StrFile = Dir() 'Note: The script had a problem with this line. It "snapped-back" to the Initialize sub and quit.
Loop
End Sub