Macros not completing but continuing

kschmeer

New Member
Joined
Oct 8, 2014
Messages
11
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...)
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:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Code:
Cont "6"
    Workbooks.Open DataFilePath, False
Does the workbook open at this point before exiting the sub? If not, then it could be that you are using the boolean "False" where a 0 or 1 would normally be used as an argument and the compiler does not know what to do with it so it goes back to the caller sub. The argument data type for the 'UpdateLinks" argument is variant, not boolean.
 
Upvote 0
Code:
Cont "6"
    Workbooks.Open DataFilePath, False
Does the workbook open at this point before exiting the sub? If not, then it could be that you are using the boolean "False" where a 0 or 1 would normally be used as an argument and the compiler does not know what to do with it so it goes back to the caller sub. The argument data type for the 'UpdateLinks" argument is variant, not boolean.


Thank you so much. Yes, that was definitely a problem. The history file was not being opened and I was getting no error messages.
 
Upvote 0
Thank you so much. Yes, that was definitely a problem. The history file was not being opened and I was getting no error messages.
Just use a numeric 0 instead of False to prevent Link updates.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top