Call ing macro from inside macro

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
I need to call a worksheet from inside a macro. The second workbook has an auto macro that runs a timer function to execute a closure . However I do not want that to run when I call it from the macro, only if I open the workbook manually. How can I add someway to break the timer loop in the calling of it from the first macro:

First macro call section
Code:
'Removed Excused JOBS
    Dim srcWB As Workbook, srcWS As Worksheet, desWS As Worksheet, LastRow As Long, x As Long
    Set desWS = ActiveWorkbook.Sheets("Open Vendor Jobs")
    LastRow = desWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim Rng As Range, RngList As Object
    Set RngList = CreateObject("Scripting.Dictionary")
    Set srcWB = Workbooks.Open("Z:\EDS\ExcludedWo.xlsm")
    Set srcWS = Sheets("EXCWOS")
    For Each Rng In srcWS.Range("A2", srcWS.Range("A" & srcWS.Rows.Count).End(xlUp))
    If Not RngList.Exists(Rng.Value) Then
    RngList.Add Rng.Value, Nothing
    End If
    Next Rng
    For x = LastRow To 2 Step -1
    If RngList.Exists(desWS.Cells(x, 1).Value) Then
    desWS.Rows(x).EntireRow.Delete
    End If
    Next x
' Close Workbook
    Application.DisplayAlerts = False
    Workbooks("ExcludedWo").Close (False)
    Application.DisplayAlerts = True



Auto timer macro in workbook
Code:
Sub SaveWb()
    Application.DisplayAlerts = False
    ThisWorkbook.Save
    Application.DisplayAlerts = True
    Application.Quit
    
  '  Application.OnTime Now + TimeValue("00:0:30"), "SaveWb"
End Sub



(In this workbook)
Private Sub Workbook_Open()
'Date_Trim()
    Sheets("EXCWOS").Select
    ActiveSheet.Unprotect "EDS"
'Sort
    Columns("A:D").Select
    ActiveWorkbook.Worksheets("EXCWOS").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("EXCWOS").Sort.SortFields.Add Key:=Range("A2:A17") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("EXCWOS").Sort
        .SetRange Range("A1:D17")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
     Range("C2").Select
'Add forumla
    lr = Range("A1").End(xlDown).Row
    If lr > 100000 Then GoTo xit
    If lr = 2 Then On Error Resume Next
    Range("C2").Select
    ActiveCell.FormulaR1C1 = "=TODAY()"
    Range("D2").Select
    ActiveCell.FormulaR1C1 = "=DAYS(RC[-2],RC[-1])"
    Range("c2:D2").Select
    Selection.AutoFill Destination:=Range("c2:D" & lr), Type:=xlFillDefault
    Range("a1").Select
'Trim old Entries
    For lr = Range("a" & Rows.Count).End(xlUp).Row To 2 Step -1
    If Range("D" & lr).Value < "1" Then Rows(lr).EntireRow.Delete
   Next
   Sheets("EXCWOS").Select
   ActiveSheet.Protect "EDS"
   
'MsgBox ("You have two minutes to update this sheet before it closes after you press enter to continue")
'Timer to close book
     Application.OnTime Now + TimeValue("00:1:30"), "SaveWb"
xit:
Sheets("EXCWOS").Select
   ActiveSheet.Protect "EDS"
   
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,214,405
Messages
6,119,320
Members
448,887
Latest member
AirOliver

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