Results 1 to 4 of 4

Using date as prefix for file name and saving it to local drive

Threaded View

Xceller Using date as prefix for file... 04-19-2015, 01:43 PM
TMS Re: Using date as prefix for... 04-19-2015, 01:52 PM
Xceller Re: Using date as prefix for... 04-19-2015, 02:09 PM
TMS Re: Using date as prefix for... 04-19-2015, 03:01 PM
  1. #1
    Forum Contributor
    Join Date
    10-22-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    114

    Using date as prefix for file name and saving it to local drive

    Hi all,

    Thanks for looking into this.

    Range("C4") = 03/31/2015

    Try to save the workbook as "2015/03/31 ABC" as file name


    This part of the code in red errors out:


    With ActiveWorkbook
    .Sheets(1).Cells(1).PasteSpecial _
    Paste:=xlPasteValuesAndNumberFormats
    .SaveAs "C:\TEST\" & sDate & sItem & ".xlsx", _
    FileFormat:=xlOpenXMLWorkbook

    .Close
    End With


    Sub PivotStockItems()
    
        Dim i As Integer
        Dim sItem As String
        Dim sDate As String
        
        sDate = Format(Worksheets("pt_AR_AGING_USD").Range("C4"), "yyyy/mm/dd")
        
        Application.ScreenUpdating = False
        Worksheets("pt_AR_AGING_USD").Select
        With ActiveSheet.PivotTables("PivotTable2")
            .PivotCache.MissingItemsLimit = xlMissingItemsNone
            .PivotCache.Refresh
            With .PivotFields("MBU")
                '---hide all items except item 1
                .PivotItems(1).Visible = True
                For i = 2 To .PivotItems.Count
                    .PivotItems(i).Visible = False
                Next
                For i = 1 To .PivotItems.Count
                    .PivotItems(i).Visible = True
                    If i <> 1 Then .PivotItems(i - 1).Visible = False
                    sItem = .PivotItems(i)
                    Cells.Copy
                    Workbooks.Add
                    With ActiveWorkbook
                        .Sheets(1).Cells(1).PasteSpecial _
                            Paste:=xlPasteValuesAndNumberFormats
                        .SaveAs "C:\TEST\" & sDate & sItem & ".xlsx", _
                            FileFormat:=xlOpenXMLWorkbook
                        .Close
                    End With
                Next i
            End With
        End With
    End Sub
    Last edited by Xceller; 04-19-2015 at 01:47 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Problem in Accessing a file in local shared drive
    By vivekdevkar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2010, 04:49 AM
  2. [SOLVED] Windows API to Determine if File is Local/Convert Path to Drive Letter
    By Johnny in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-10-2006, 09:30 AM
  3. [SOLVED] Hyperlinks - Move file to local drive, all links break
    By Shawn McGowen in forum Excel General
    Replies: 1
    Last Post: 03-08-2006, 08:52 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