Consulting

Results 1 to 2 of 2

Thread: click save csv files

  1. #1

    click save csv files

    I'm using this code to batch run a macro to a folder of files.

    I have no problem with saving xlsx files, but when I run this macro on a folder of csv files I have to click save every time. Is there a way to suppress the save messages or just some vba to batch convert csv's to xlsx's?

    [vba]Sub runrepl()

    Dim F As String
    Dim roww As Long
    roww = 0
    Dim FileLocSpec As String
    FileLocSpec = "C:\ex\*.*"
    F = Dir(FileLocSpec)
    Do Until F = ""
    roww = roww + 1
    Cells(roww, 1).Value = F
    F = Dir
    Loop
    Set r = Range("A1")
    While r.Value <> ""
    Workbooks.Open Filename:="C:\ex\" & r.Value
    Call formheader
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    Set r = r.Offset(1, 0)
    Wend
    End Sub[/vba]

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi there,

    I haven't tested this at all, but you could try just disabling the alerts:

    Application.DisplayAlerts = False

    Just remember to turn it on afterwards.

    If that doesn't solve it, then you may want to test the file extension and do a SaveAs command on it to save it either to CSV or XLSX (whatever your preference)

    ActiveWorkbook.SaveAs Filename:="C:\ex\" & r.Value, FileFormat:=xlCSV
    or
    ActiveWorkbook.SaveAs Filename:="C:\ex\" & r.Value, FileFormat:=xlOpenXMLWorkbook
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •