+ Reply to Thread
Results 1 to 3 of 3

Save .csv file as an Excel file while allowing user to choose directory and filename

Hybrid View

  1. #1
    Registered User
    Join Date
    01-10-2013
    Location
    Boston, MA USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Save .csv file as an Excel file while allowing user to choose directory and filename

    Hi,

    I am trying to Save .csv file as an Excel file while allowing user to choose directory and filename. In other words I have a .csv file that has a macro run on it that moves data around and the like. That is fine but when that is done I need the macro to bring up the prompt/window so the user to save this file with whatever filename they want and whatever excel version they want. Additionally I wanted to put in a default directory to the area where the file would most likely be saved to minimize user navigation through the LAN (yes the user is demanding but does sign my paycheck ).

    I tried "getsavefilenameas" and I have tried several other methods (that worked when it was excel to excel) however I keep getting file type errors that say the file type does not match the file extension and thus the file cannot be opened.

    Any help would be greatly appreciated.

    Thanks

  2. #2
    Registered User
    Join Date
    01-10-2013
    Location
    Boston, MA USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Save .csv file as an Excel file while allowing user to choose directory and filename

    Any help would be greatly appreciated.

  3. #3
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Save .csv file as an Excel file while allowing user to choose directory and filename

    Hey,

    So I just wrote this up quick and may be buggy but I dont have Excel on this computer.

    Sub GetPath()
    
    Dim MyPath as String
    Dim MyName as String       'Define these however you want. UserForm, or put in a cell, etc...
    Dim FileType as String	    'Define these however you want. UserForm, or put in a cell, etc...
    
    MyPath = Application.GetOpenFilename		'Opens the Browser Window
    
    If MyPath = False Then				        'If no file was selected
        MsgBox "Nothing Chosen"					
    Else
        Cells(21, 8) = MyPath				'Define my path
    	ActiveSheet.SaveAs Filename:=MyPath & "\" & MyName & "." & FileType, FileFormat _		'Try to Save
            :=xlCSVMSDOS, CreateBackup:=False 	' Notice that MyName and FileType are defined
    End If
    
    End Sub
    Just attach that macro to a button.
    When you click the button, it brings up a browser window that lets you save the directory.
    You can then try to save.

    You may also want an Application.DisplayAlerts = False somewhere in the because you will get messages about saving CSVs cause they dont support some of the stuff or something or other.

    I know that this reply was very quick and not very thorough.

    Let me know if its unclear

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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