+ Reply to Thread
Results 1 to 7 of 7

Opening all CSVs in a folder, formatting and then printing.

  1. #1
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Opening all CSVs in a folder, formatting and then printing.

    We have program that exports a calculator into CSV format. Doing so makes all the columns the same size and data is cut off. I can't change how the program exports. All the files are exported into one folder each day and at the end of the day all of these are printed. I need a macro that can be run at the end of the day that will open each file in the folder and AutoFit and set it to 1 page height and width then print that file and then close. Saving doesn't do any good since the CSV just reverts back to the busted look. The file path will look something like this, **\\arr011\Image\Calc\Environment\2018\06\20** except the dates will obviously change. So opening a file window to the Environment level would be great. This way if they want to reprint any old folders they could.

    I can record a macro for autofit and for 1 page, but it is extremely long for something so basic. I think just like this might work, but I don't know how to make that work with my other tasks. Also, there may be a lot of these in a folder. A manual process is extremely tedious.

    I've attached a sample workbook. Not sure if you need it since the settings are applied to the entire workbook and content doesn't matter but if it helps great!

    Please Login or Register  to view this content.
    Summarized

    1. Open file window,
    2. Select folder
    3. Open CSV file
    4. Format
    __4a. Autofit Columns
    __4b. Width/Height 1 page
    5. Print
    6. Close
    7. Repeat for all files in


    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Opening all CSVs in a folder, formatting and then printing.


    Just activate the Macro Recorder and operate manually for at least the first text file then post here the generated code …

  3. #3
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Opening all CSVs in a folder, formatting and then printing.

    You mean like this?

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Opening all CSVs in a folder, formatting and then printing.

    So I can get it down to this

    Please Login or Register  to view this content.

    Then I need to print, close and repeat.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this ‼


    According to your material :

    PHP Code: 
    Sub Demo1()
             
    Dim P$, F$
                 
    ThisWorkbook.Path
        With Application
    .FileDialog(msoFileDialogFolderPicker)
                 .
    ButtonName "Choose"
            
    .InitialFileName Left(PInStrRev(P"\"))
                .InitialView = msoFileDialogViewList
                      .Title = Space$(20) & "
    Choose the CSV folder :"
             If .Show Then P = .SelectedItems(1) & "
    \" Else Exit Sub
        End With
                 Application.ScreenUpdating = False
                 F = Dir(P & "
    *.csv")
        Do Until F = ""
            With Workbooks.Open(P & F).Worksheets(1)
                     .UsedRange.Columns.AutoFit
                With .PageSetup
                     .Zoom = False
                     .FitToPagesTall = 1
                     .FitToPagesWide = 1
                End With
                     .PrintOut
                     .Parent.Close False
            End With
                 F = Dir
        Loop
                 Application.ScreenUpdating = True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Opening all CSVs in a folder, formatting and then printing.

    Thanks. How do I make it open to the correct folder path already?

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Opening all CSVs in a folder, formatting and then printing.


    Use directly the path in Dir function instead of asking to choose one …

+ 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. [SOLVED] Making a folder and Opening the folder
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-03-2016, 08:20 AM
  2. [SOLVED] Specific folder when opening windows popup folder selection with msoFileDialogFolderPicker
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-18-2015, 11:05 AM
  3. Opening files in Excel 2013 from a folder without opening Excel first
    By Percy47746 in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 01-10-2015, 07:28 AM
  4. Replies: 4
    Last Post: 03-12-2014, 02:06 AM
  5. Opening a folder
    By Daminc in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-23-2006, 07:47 AM
  6. [SOLVED] when opening folder
    By Brian Thompson via OfficeKB.com in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 12-18-2005, 06:55 PM
  7. [SOLVED] "Folder Select" Dialogue - Opening multiple files from selected folder
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-30-2005, 10:05 AM

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