+ Reply to Thread
Results 1 to 5 of 5

Cannot Call a macro within a macro

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Cannot Call a macro within a macro

    Dear experts,

    I'm still a beginner in VBA, and only capable of doing cut & paste works to make my own macro.

    I've completed the whole macro (which will call up another macro), but if I press F5 (from within the VBA Project) the codes can call up another macro and complete to the end. However if I press the macro hotkey (Ctrl+shift+o), it will stop before the line calling up another macro). I now list below my codes for your checking & advice :

    Sub OpenCF_File()
    
    'Open each Project Cashflow file, and Copy from Monthly Cashflow Report (for new month cashflow) to this Project Cashflow file
    '
    'Ctrl+ Shft + O
    '
    Dim MyFiles As String
    Dim CurrentFolder As String
    Dim FileName As String
    Dim myPath As String
    Dim UniqueName As Boolean
    
    UniqueName = False
    
     Application.AskToUpdateLinks = False
     Application.DisplayAlerts = False
     
     MyFiles = Dir(ActiveWorkbook.Path & "\*Cashflow.xl*")
     
     Do While MyFiles <> ""
       
     Workbooks.Open ActiveWorkbook.Path & "\" & MyFiles
      
      Call CopyPCF
      
      ActiveWorkbook.Close SaveChanges:=True
      
      On Error GoTo 0
      
       MyFiles = Dir
       Loop
        
    Application.AskToUpdateLinks = True
    Application.DisplayAlerts = True
     
    
    Exit Sub
    
    End Sub
    
    Sub CopyPCF()
    '
    ' Insert new Cashflow Month with linkage to new month of CFR file
    '
    ' Ctrl+ Shft + P
    '
            
        Workbooks(2).Activate
        Dim P_Code As String
        Dim Dtl_Sheet As String
           
        P_Code = Range("PCode")
        Dtl_Sheet = Range("DtlSheet")
        
        Workbooks(1).Activate
        
        Dim CashflowWB As String
        CashflowWB = ActiveWorkbook.Name
        
        Workbooks(1).Sheets(Dtl_Sheet).Select
        Rows("9:9").Select
        Selection.Find(What:=P_Code, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
            , MatchByte:=False, SearchFormat:=False).Select
        ActiveCell.EntireColumn.Select
        
        Workbooks(2).Activate
            
        Columns("E:F").Select
        Selection.Copy
        Selection.Insert Shift:=xlToRight
        
        Range("E1") = CashflowWB
        
        Range("E6") = "=+EOMONTH(G6,1)"
        Range("E6").Copy
        Range("E6").PasteSpecial Paste:=xlPasteValues     'Date : avoid EOMONTH error for 2003
            
        Columns("D:D").Select
        Selection.Replace What:=Range("G1"), Replacement:=Range("E1"), LookAt:=xlPart _
            , SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
          
        
        Range("CI").Select
        Selection.Copy
        ActiveCell.Offset(0, 1).Select
        Selection.PasteSpecial Paste:=xlPasteValues
        
        Range("CO_COST").Select
        Selection.Copy
        ActiveCell.Offset(0, 1).Select
        Selection.PasteSpecial Paste:=xlPasteValues
        
        Range("CO_PAYABLE").Select
        Selection.Copy
        ActiveCell.Offset(0, 1).Select
        Selection.PasteSpecial Paste:=xlPasteValues
        
        ActiveCell.Offset(10, 0).Select
        
    End Sub

    Thanks in advance

    Edward

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,320

    Re: Cannot Call a macro within a macro

    Try using a shortcut key combination that doesn't involve the Shift key.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Cannot Call a macro within a macro

    Great ! The code really can finish to the end !
    But why can't I use hotkey Ctrl+Shft, what is the logic behind ?

    Thx anyway.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,320

    Re: Cannot Call a macro within a macro

    It's a bug in Excel.

  5. #5
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Cannot Call a macro within a macro

    Thanks so much for your advice !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] I want to call a macro within a macro and loop it and save the each output in a sheet
    By Sriramroxx in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-12-2018, 01:29 AM
  2. Outlook New_Mail Event Macro to Call Excel Macro
    By christopheralan88 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2015, 06:28 PM
  3. Replies: 2
    Last Post: 08-13-2014, 06:39 PM
  4. Replies: 1
    Last Post: 08-13-2014, 05:46 PM
  5. Calling macro 10 times, add header list to macro call only once
    By capson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-05-2013, 09:42 AM
  6. [SOLVED] Call another Macro or Stop Macro Based on MsgBox Yes or No
    By GStone in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-03-2012, 05:59 PM
  7. [SOLVED] Excel Macro call Word Macro with Parameters
    By Bill Sturdevant in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-25-2005, 01:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1