+ Reply to Thread
Results 1 to 2 of 2

Export CSV file in Specific naming format

Hybrid View

  1. #1
    Registered User
    Join Date
    08-02-2013
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    41

    Export CSV file in Specific naming format

    Hi, I have the below code SaveFileAs that's saving the file with a specific format and I would like to export the file in CSV format and I do have the below code for it, however is there any way to merge the CSV mcro in SaveAs or provide the specific format while Saving CSV macro.

    The output has to be in certain format and with 2 of the below code, I am unable to save it as one file.

    Any help would be greatly appreciated, Had been stuck for sometime

    
    Sub SaveFileAs()
     
        '-----Directory Properties----'
        Dim fso As Object, _
        ShellApp As Object, _
        File As Object, _
        SubFolder As Object, _
        Directory As String, _
        Problem As Boolean, _
        ExcelVer As Integer
         
        '-----File Properties----------'
        Dim strName As String
        Dim period As String
        Dim dateStamp As String
        Dim timeStamp As String
        Dim fileName As String
        Dim userId As String
         
        '-----start HAVE USERS SELECT DIRECTORIES-----'
             
        '------Create objects to get a listing of all files in the directory
        Set fso = CreateObject("Scripting.FileSystemObject")
         
        '--------Prompt user to select a directory-----'
        Do
            Problem = False
            Set ShellApp = CreateObject("Shell.Application"). _
            Browseforfolder(0, "Please choose a folder", 0, "c:\\")
             
            On Error Resume Next
            '-----Evaluate if directory is valid-----'
            Directory = ShellApp.self.Path
            Set SubFolder = fso.GetFolder(Directory).Files
            If Err.Number <> 0 Then
                If MsgBox("You did not choose a valid directory!" & vbCrLf & _
                "Would you like to try again?", vbYesNoCancel, _
                "Directory Required") <> vbYes Then Exit Sub
                Problem = True
            End If
            On Error GoTo 0
        Loop Until Problem = False
        '-------end USERS SELECT DIRECTORIES------'
        
        '------start FILE SAVE----------'
        dateStamp = Format(FormatDateTime(Now, vbShortDate), "MM-DD-YYYY")
        timeStamp = Format(FormatDateTime(Now, vbLongTime), "hms")
       fileName = Directory & "\" & strName & "~" & period & "~" & userId & "~WorkID~" & dateStamp & "~" & timeStamp
        MsgBox "Saving File ..." & fileName
        
        saveFlag = 1
        ActiveWorkbook.SaveAs fileName
        'ActiveWorkbook.SaveAs Directory & "\" & "SCF 2008 Template_Q108_Hv1.1"
        saveFlag = 0
       
       
    End Sub
    
    Sub CSV()
    
    
    Dim SrcRg As Range
    Dim CurrRow As Range
    Dim CurrCell As Range
    Dim CurrTextStr As String
    Dim ListSep As String
    Dim FName As Variant
    Dim delimit As String
    
    FName = Application.GetSaveAsFilename("", "CSV File (*.csv), *.csv")
    
    ListSep = Application.International(xlListSeparator)
      Set SrcRg = Sheets("Sheet2").UsedRange
      
      Open FName For Output As #1
      For Each CurrRow In SrcRg.Rows
        CurrTextStr = ""
        For Each CurrCell In CurrRow.Cells
          CurrTextStr = CurrTextStr & """" & CurrCell.Value & """" & ListSep
        Next
        While Right(CurrTextStr, 1) = ListSep
          CurrTextStr = Left(CurrTextStr, Len(CurrTextStr) - 1)
        Wend
        Print #1, CurrTextStr
      Next
     Close #1
    
    
    End Sub
    Last edited by momer; 08-27-2013 at 05:59 PM.

  2. #2
    Registered User
    Join Date
    08-02-2013
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Export CSV file in Specific naming format

    I am trying to insert a variable filename under first doubt quotes(filename),although not sure if it takes variable.
    FName = Application.GetSaveAsFilename("", "CSV File (*.csv), *.csv")

+ 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. VBScript, export file to call date specific
    By andy.k in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-05-2013, 09:44 AM
  2. Naming the Excel File Name in a specified Format
    By Satya.payal in forum Excel General
    Replies: 0
    Last Post: 01-24-2012, 01:12 PM
  3. Replies: 4
    Last Post: 09-08-2005, 03:05 PM
  4. Format of CSV File in export
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-08-2005, 03:05 PM
  5. Format of CSV File in export
    By [email protected] in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-08-2005, 03: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