+ Reply to Thread
Results 1 to 6 of 6

Help with VBA to automate saving file in specific location and file name with dates

  1. #1
    Registered User
    Join Date
    02-21-2017
    Location
    Norway
    MS-Off Ver
    2016 (Win10)
    Posts
    76

    Help with VBA to automate saving file in specific location and file name with dates

    Hi,

    I have here a simple file that is downloaded as csv from a very restricted database and data is saved as excel every month. I need to reformat it into "nicer" format before uploading it to a sharepoint site so that other users can refer to the data for information.

    The file is renamed to indicate "Matrix_25.06.2017" to save in the sharepoint site.

    How do I add this into the VBA so that it will automatically reformat and save the file in the right location with the right name?

    I have this VBA script that is recorded by the excel macro.

    I can't seem to be able to attach file now.

    Sub MatrixReformat1()
    '
    ' MatrixReformat1 Macro
    '

    '
    Range("A1:M1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    Columns("A:M").Select
    Columns("A:M").EntireColumn.AutoFit
    Range("A1:M1").Select
    Selection.Font.Bold = True
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
    End With
    Columns("C:H").Select
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Columns("I:I").Select
    Selection.Style = "Comma"
    Selection.NumberFormat = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
    Columns("L:M").Select
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Range("I14").Select
    End Sub
    Attached Files Attached Files
    Last edited by fornight; 07-10-2017 at 08:07 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Help with VBA to automate saving file in specific location and file name with dates

    Please Login or Register  to view this content.
    Will save in the target folder with today's date in the file name, as .xlsx file

  3. #3
    Registered User
    Join Date
    02-21-2017
    Location
    Norway
    MS-Off Ver
    2016 (Win10)
    Posts
    76

    Re: Help with VBA to automate saving file in specific location and file name with dates

    Just insert this sentence right before "End Sub"?

  4. #4
    Registered User
    Join Date
    02-21-2017
    Location
    Norway
    MS-Off Ver
    2016 (Win10)
    Posts
    76

    Re: Help with VBA to automate saving file in specific location and file name with dates

    I received an error message.

    It said

    Run time error 10041:
    VB projects and xlm sheets cannot be saved in a macro-free workbook.

  5. #5
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Help with VBA to automate saving file in specific location and file name with dates

    Sorry, my mistake. Since the code is contained in the workbook we are saving (i.e. ThisWorkbook) you will need to save as .xlsm (macro-enabled). Try:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-21-2017
    Location
    Norway
    MS-Off Ver
    2016 (Win10)
    Posts
    76

    Re: Help with VBA to automate saving file in specific location and file name with dates

    Yes, it works!!!

    Thanks!!!!

+ 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. saving a file in a remote location
    By santhoshkuttan in forum Excel General
    Replies: 7
    Last Post: 11-08-2016, 12:44 PM
  2. Saving a Workbook With A Specific File Name in a Specific Location
    By kyjae in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2016, 02:49 PM
  3. Macro to search file location for presence of a specific file
    By Student1990 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2014, 02:31 AM
  4. [SOLVED] Saving file in a date specific location
    By mayurpatil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2013, 01:30 AM
  5. automate saving a worksheet with file name found in cell
    By TLMI in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-15-2011, 05:08 PM
  6. Saving a File with specific file name using Macro
    By LstarS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-19-2009, 06:13 AM
  7. VBA for saving a file to a specific location
    By TimT in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-07-2005, 04: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