File Save Dialog Box !

achalrikhi

New Member
Joined
Nov 20, 2013
Messages
38
Dear Friends,

Hello, I have a project. In that I am importing a csv file, change all the necessary alteration and export it in a txt format. Everything is going just fine.

This is what actually happens :

I have imported a .CSV file by " xxx " name. Now when I export it in a .txt format, the user need to put a name with ".txt" at the end of the file name.

What I want :

When a user exports the file in a .txt format, the " FileDialogSaveAs " box should come with a SAME file name which was the name of the IMPORTED file which was a .CSV.

I am using the code is :

Private Sub CmdCashTextConvert_Click()
Dim intChoice As Integer
Dim strPath As String


'make the file dialog visible to the user
intChoice = Application.FileDialog(msoFileDialogSaveAs).Show
'determine what choice the user made
If intChoice <> 0 Then
'get the file path selected by the user
strPath = Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1)
'displays the result in a message box
Call MsgBox(strPath, vbInformation, "Save Path")


Select Case MsgBox(" Do you want to convert CSV file to text file ?", vbYesNo)
Case vbYes
DoCmd.TransferText acExportDelim, "Cash Export Specification", "Equity", strPath, True


MsgBox (" CSV file converted to text file successfully ")
End Select


DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM TblCash;"
DoCmd.SetWarnings True
End If
End Sub

Please guide

Thanks & Regards

Achal
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
CSV files are ALREADY text files. You can just rename the file to .txt.
filecopy file.csv, file.txt

Or do you need to process the data. I dont see this here.
if so,
Code:
Public Function UserSaveFileAs (ByVal pvFile)
Dim strTable As String
Dim strFilePath As String
Dim sDialog As String, sDecr  As String, sExt As String
Dim fd As FileDialog


Set fd = Application.FileDialog(msoFileDialogSaveAs)   '<----!!  MUST ADD REFERENCE : Microsoft Office 11.0 Object Library
With fd
    .AllowMultiSelect = False
    .Title = "Locate a file to Import"
    .ButtonName = "Export"
    .InitialFileName = pvFile
    .InitialView = msoFileDialogViewList    'msoFileDialogViewThumbnail
     If .show = -1 Then
        UserSaveFileAs = fd.SelectedItems(1)
     End If
End With
Set fd = Nothing
End Function
 
Upvote 0

Forum statistics

Threads
1,221,851
Messages
6,162,429
Members
451,765
Latest member
craigvan888

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top