Results 1 to 2 of 2

Open a new workbook, save with date from cell in workbook.

Threaded View

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    NE
    MS-Off Ver
    2013
    Posts
    42

    Open a new workbook, save with date from cell in workbook.

    I have VBA code to open a new workbook here is my problem:

    I want open a new workbook(2) and save it with a date to be pasted in B1.

    I want to then activate workbook(1) and copy selected cells and paste them into workbook2.

    Then save workbook2 with the following title (SF_GR110_MMDD)

    What I am trying to accomplish is not overwriting this file every time it is created.

    Here is the code I have already:

    '2. Creates the csv file for Oracle and sends it to the Livestock\Files folder on your c drive.
        Application.DisplayAlerts = False
        Set NewBook = Workbooks.Add
        With NewBook
            .SaveAs filename:= _
                "C:\livestock\files\" & Format("SF_GR110") & "_" & ".csv", FileFormat _
                :=xlTextPrinter, CreateBackup:=False
        End With
        Application.DisplayAlerts = True
        Workbooks("SD Grain.xlsm").Activate
        Sheets("CSV").Activate
        Worksheets("CSV").Range("B11:B14").Copy
        Workbooks("SF_GR110_.csv").Activate
        ActiveSheet.Range("a1").PasteSpecial _
                    Paste:=xlPasteValuesAndNumberFormats
        Selection.Columns.AutoFit
        ActiveWindow.DisplayZeros = False
        Range("A1").Select
        Application.CutCopyMode = False
        Workbooks("SF_GR110_.csv").Close SaveChanges:=True
        Workbooks("SD Grain.xlsm").Activate
        Application.CutCopyMode = False
    Thanks for any help.

    I have been trying this code in the file name but it gives me a Syntax error
    - plus I can't figure out how to make the file save revert back to the date:

    "C:\livestock\files\" & Format("SF_GR110") & "_" & (Sheet1.Range("B1"), "mmdd") & ".csv", FileFormat _

    Here is what I did:

    Set newbook = Workbooks.Add
        Workbooks("SD Grain.xlsm").Activate
        Sheets("CSV").Activate
        Worksheets("CSV").Range("B11:B14").Copy
        newbook.Activate
        ActiveSheet.Range("a1").PasteSpecial _
                    Paste:=xlPasteValuesAndNumberFormats
        Selection.Columns.AutoFit
        ActiveWindow.DisplayZeros = False
        Range("A1").Select
        Application.CutCopyMode = False
        With newbook
            .SaveAs filename:="C:\livestock\files\SF_GR110_" & Format(Sheet1.Range("H3"), "mmdd") & ".csv" _
                , FileFormat:=xlTextPrinter, CreateBackup:=False
                     .Close savechanges:=True
        End With
        Workbooks("SD Grain.xlsm").Activate
        Application.CutCopyMode = False
    Last edited by rlh; 08-22-2013 at 10:16 AM. Reason: solved it on my own

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to open,save and close another workbook from the current workbook using macro?
    By ravikumar00008 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-15-2012, 10:42 AM
  2. Always open workbook Macro to save as date and start a new day
    By JazzyBear in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2012, 08:08 AM
  3. Save an open workbook, then open template workbook and close the saved workbook
    By ondvirg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2009, 10:20 PM
  4. open workbook then save as different workbook dependant on a1
    By excellentexcel in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 02-15-2009, 09:15 AM
  5. Using interop.excel to open a workbook, the workbook doesn't ask to save changes.
    By milmans@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-28-2005, 06:30 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