+ Reply to Thread
Results 1 to 4 of 4

Close workbooks and move in and out of workbooks in VBA

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    214

    Close workbooks and move in and out of workbooks in VBA

    Dear all,

    Thank you for reading my post.

    My macro is very simple. Basically the main workbook opens 2 files at a time performs a calculate in the main workbook and then copies and pastes information in 3 ranges. Then closes the two open workbooks and loops and performs same operations until it hits the maximum loops.

    My macro is as follows and I have 3 question in capital letters.

    Sorry i am a beginner and appreciate your help, regards John



    Sub Import()
    
    Dim CurrentLoop As Long
    
    
    Range("PV_Destination_EB").Clear
    Range("PV_Destination_NB").Clear
    Range("Clear_FPOF").Clear
    
    
    For CurrentLoop = 1 To [Maximum_Loops]
        Range("Current_Loop") = CurrentLoop
        Sheets("Sheet1").Calculate
        
        Workbooks.Open Filename:=[Current_EB_FPOF_Location]
        Windows("FPOF Summary 1.1.xlsm").Activate ' NOT SURE WHY I NEED THIS BUT DOES NOT WORK WITHOUT? HOW NOT TO USE THE FILE NAME?
        
        Workbooks.Open Filename:=[Current_NB_FPOF_Location]
        Windows("FPOF Summary 1.1.xlsm").Activate ' NOT SURE WHY I NEED THIS BUT DOES NOT WORK WITHOUT? HOW NOT TO USE THE FILE NAME?
        
        Sheets("Sheet1").Calculate
            
        Range("Formula_FPOF").Copy
        Range([Destination_Range1]).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Application.CutCopyMode = False
                  
        Range("Formula_FPOF").Copy
        Range([Destination_Range1]).Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
               
        Range("PV_Source_EB").Copy
        Range("PV_Destination_EB").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        
        Range("PV_Source_EB").Copy
        Range("PV_Destination_EB").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
                
        Range("PV_Source_NB").Copy
        Range("PV_Destination_NB").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        
        Range("PV_Source_NB").Copy
        Range("PV_Destination_NB").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
           
        Workbooks.Close Filename:=[Current_NB_FPOF_Location]
        Workbooks.Close Filename:=[Current_EB_FPOF_Location]
        Windows("FPOF Summary 1.1.xlsm").Activate
        
        ' HOW TO CLOSE THE TWO WORKBOOKS OPENED ABOVE?
        
        If Range("Current_Loop") > Range("Maximum_Loops") Then Exit Sub
    Next_Data:    Next
               
    End Sub
    Last edited by John Vieren; 12-28-2009 at 04:08 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: Close workbooks and move in and out of workbooks in VBA

    Try to utilize this code to fit in with your existing code
    http://support.microsoft.com/kb/147742

  3. #3
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    214

    Re: Close workbooks and move in and out of workbooks in VBA

    Hi

    Thanks for your response but that did not help.

    Regards John

  4. #4
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    214

    Re: Close workbooks and move in and out of workbooks in VBA

    Hi I marked it as solved so that you dont delete my othe post.

    But honestly its not solved.

    Regards John



    Moderator note:
    discussion continues in this thread
    Last edited by teylyn; 12-28-2009 at 04:26 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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