In a nutshell (does that date me?)...
The main macro calls macro A.
Macro A calls macro B.
Macro B executes to a point. Does not complete. Exits.
Macro A does not continue after the call to Macro B.
Main macro continues and executes correctly to the end of the program.
In my code below:
Sub Cont just refreshes the screen, displays the message and waits for user input to continue or stop. Just a debugging tool to follow the execution.
All the variables are ok, no problem there.
main macro = Sub MainSub
macro A = Sub CreateFile
macro B = Sub ParcelLienOrder
Here is my code followed by the resulting displays...
(it's a bunch of code, but it should be easy to follow...)
When executed, here is the results displayed from the Cont debugging tool:
Start
1
2
3
4
5
6
Opening: history file
End
Note: It never executes lines Cont 7 - Cont 10 in the macro C, and also does not execute Cont 11 and Cont 12 in macro B from after calling macro B.
MainSub continues correctly.
Issues I could find similar to this has to do with the shift and esc keys being depressed. This is not the case. This is just code executing.
I have tried breaking up Macro C into other macros and calling them from the MainSub after the Macro A call, but that doesn't work either. It got a few more commands to work, but then ended early in the new macro to return to the MainSub again...
Looking for that Excel VBA guru here...
Thanks.
The main macro calls macro A.
Macro A calls macro B.
Macro B executes to a point. Does not complete. Exits.
Macro A does not continue after the call to Macro B.
Main macro continues and executes correctly to the end of the program.
In my code below:
Sub Cont just refreshes the screen, displays the message and waits for user input to continue or stop. Just a debugging tool to follow the execution.
All the variables are ok, no problem there.
main macro = Sub MainSub
macro A = Sub CreateFile
macro B = Sub ParcelLienOrder
Here is my code followed by the resulting displays...
(it's a bunch of code, but it should be easy to follow...)
Code:
Sub MainSub()
...
Cont "Start"
CreateFile "Notes" 'create the Notes file
Cont "End"
...
End Sub
Private Sub CreateFile(fType As String)
'Open a new file, copy in data worksheet as the master worksheet (Co Parcels).
'Then create parcel worksheets from the Letters file template.
Dim fName As String
Dim fTmp As String
If fType = "Notes" Then
fName = ArchFileNotes
fTmp = c_TmpNote
End If
If fType = "Letters" Then
fName = ArchFileLetters
fTmp = c_TmpLet
End If
'create/open a new Excel file, name it for the fType file. This is an executable
ChDir c_Dir
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=fName
'copy the parcel data into the new file
CopyWorksheet ProgramFile, c_Data, fName, "Sheet1"
Sheets("Sheet1").Name = c_Mstr
'copy the template worksheet data into the new file
CopyWorksheet ProgramFile, fTmp, fName, "Sheet2"
Sheets("Sheet2").Name = fTmp
CreateParcelTabs fName, fTmp
Cont "1"
'delete Sheet3 worksheets
Application.DisplayAlerts = False
Sheets("Sheet3").Delete
Application.DisplayAlerts = True
Cont "2"
Sheets(c_Mstr).Select
Range("A1").Select
Cont "3"
ParcelLienOrder fName 'order the parcel tabs in order relating to past years liens
Cont "11"
SaveCloseFile fName, c_Dir & fName, True
Cont "12"
End Sub 'CreateFile
Sub ParcelLienOrder(fName As String)
'In the "Foreclosure History" subfolder there is a file named "Foreclosure History rpt.xlsx
'This file lists all the parcels who have had a lien, and the number of liens.
'Use this file to order the parcels tabs in order of the number of liens a property has had.
Dim critRange As String
Dim refCell As String
Cont "4"
'create temp lien worksheet for this process
Sheets.Add().Name = c_TmpLien
Cont "5"
'get the Foreclosure History report file with the lien counts
DataFilePath = c_Dir & "Foreclosure History\Foreclosure History rpt.xlsx"
Cont "6"
Workbooks.Open DataFilePath, False
Cont "7"
DataFile = ParsePathName(DataFilePath, "F") 'get just the file name, no path
Cont "8"
CopyWorksheet DataFile, "LienCount", fName, c_TmpLien
Cont "9"
ReleaseFile DataFile, True
Cont "10"
End Sub 'ParcelLienOrder
When executed, here is the results displayed from the Cont debugging tool:
Start
1
2
3
4
5
6
Opening: history file
End
Note: It never executes lines Cont 7 - Cont 10 in the macro C, and also does not execute Cont 11 and Cont 12 in macro B from after calling macro B.
MainSub continues correctly.
Issues I could find similar to this has to do with the shift and esc keys being depressed. This is not the case. This is just code executing.
I have tried breaking up Macro C into other macros and calling them from the MainSub after the Macro A call, but that doesn't work either. It got a few more commands to work, but then ended early in the new macro to return to the MainSub again...
Looking for that Excel VBA guru here...
Thanks.
Last edited by a moderator: