Results 1 to 11 of 11

Loop to save all versions of report using drop down

Threaded View

  1. #1
    Registered User
    Join Date
    11-18-2016
    Location
    Denver, Colorado
    MS-Off Ver
    2013 64-bit
    Posts
    5

    Unhappy Loop to save all versions of report using drop down

    Hello and thank you for any help I can get with this!

    I am trying to use the following Macro to save all versions of a report, but I don't know how to create the loop. The reports value change based off of a drop down cell and I want to save every version of that drop down to a designated folder. My current Marco is causing the saved files to crash excel and I am not sure why.

    My drop down is in cell C2 and it is the data validation is based on O16:O159

    I am copy and pasting several tabs to a new worksheet because I need to save the report as values since I am currently using a cube connection that is not accessible by the end user.

    Any help on this would be greatly appreciated!

    This is the current Macro I am using:

    Sub SaveAsValues()
        
        'Save Monthly Report as Values in new workbook
        Dim wkb As Excel.Workbook
        Dim newWB As Excel.Workbook
        Dim wks As Excel.Worksheet
        Dim newWks As Excel.Worksheet
        Dim sheets As Variant
        Dim varName As Variant
        '----------------------------------------------
        
        Application.DisplayAlerts = False
        
        'Define the names of worksheets to be copied.
        sheets = VBA.Array("FTE Variance (8)", "Mill Levy Summary (7)", "Spending Graph (6)", "Forecasting Tool (5)", "16-17 Full Year (4)", "16-17 YTD (3)", "16-17 Current Month (2)", "Remaining Balance (1)", "Monthly Report Cover Page")
        
        
        'Create referenece to the current Excel workbook and to the destination workbook.
        Set wkb = Excel.ThisWorkbook
        Set newWkb = Excel.Workbooks.Add
        
        ActiveWorkbook.SaveAs "Book1"
        
            Workbooks("Book1").Connections.AddFromFile _
            "C:\Users\PAUL_CYR\Documents\My Data Sources\fin-dmart-prod LAWSONDW GL SUMMARY CUBE.odc"
        
        For Each varName In sheets
        
            'Clear reference to the [wks] variable.
            Set wks = Nothing
            
            'Check if there is a worksheet with such name
            On Error Resume Next
            Set wks = wkb.Worksheets(VBA.CStr(varName))
            On Error GoTo 0
            
            'If worksheet with such neam is not found, those instructions are skipped.
            If Not wks Is Nothing Then
            
                'Copy this worksheet to a new workbook
                Call wks.Copy(newWkb.Worksheets(1))
                
                Application.CalculateUntilAsyncQueriesDone
                
                'Get the reference to the copy of this worksheet and paste
                'all its content as values
                Set newWks = newWkb.Worksheets(wks.Name)
                With newWks
                    Call .Cells.Copy
                    Call .Range("a1").PasteSpecial(Paste:=xlValues)
                End With
                
            End If
            
        Next varName
    
        ActiveWorkbook.SaveAs Filename:="H:\1_School Support\RBR FY17\Monthly Reports\October\" & Range("B1").Text & " - Monthly Report - October.xlsx"
    
        Application.DisplayAlerts = True
        
        
    End Sub
    Last edited by paul_cyr; 11-18-2016 at 03:21 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA to Open Monarch10 and run Model > Report and save final report : Please Assist
    By naresh73 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2016, 04:23 AM
  2. Drop-down lists in older versions of Excel
    By nclark52 in forum Excel General
    Replies: 1
    Last Post: 09-29-2015, 05:52 PM
  3. Replies: 0
    Last Post: 07-27-2015, 01:06 PM
  4. Replies: 1
    Last Post: 09-05-2013, 02:39 PM
  5. Save 15 File versions by changing one value
    By Junebug3 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-21-2013, 05:43 AM
  6. how to save different versions
    By sharc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-02-2008, 04:20 PM
  7. Save As csv file between Excel versions
    By EdwardH in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2005, 01:06 PM

Tags for this Thread

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