Prompt User for Filename (Last Time)

crobertson

New Member
Joined
Nov 14, 2005
Messages
32
Ok,

Code:
Sub X()
    SaveAsDelimited Range("'MAS90 Data'!A1:B4"), ","
 End Sub
 
Sub SaveAsDelimited(Data As Range, Delimiter As String)
    Dim Fname As Variant
    Dim strBuf As String
    Dim rngTemp As Range
    Dim rngCell As Range
    Dim intUnit As Integer
    Dim strDelimit As String
    Dim strPath As String
    Dim strName As String
    
    MsgBox "Please enter the job number as the filename."
    Fname = Application.GetSaveAsFilename( _
    fileFilter:="CSV (*.csv), *.csv")
    If Fname = False Then
    MsgBox "You didn't enter a filename!"
    End If
    
    intUnit = FreeFile
    Open Fname For Output As intUnit
    For Each rngTemp In Data.Rows
        strBuf = ""
        strDelimit = ""
        For Each rngCell In rngTemp.Cells
            If InStr(rngCell.Text, ",") > 0 Then
                               strBuf = strBuf & strDelimit & """" & rngCell.Text & """"
            Else
                strBuf = strBuf & strDelimit & rngCell.Text
            End If
            strDelimit = Delimiter
        Next
        Print #intUnit, strBuf
    Next
    Close intUnit
      
End Sub

This is working great, but here is my dilema, I now have to get a selection from a combo box + user input for the filename.

Any help is greatly appreciated!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
What's the actual question?

Do you want to combine the value from the combobox with the value from GetSaveAsFileName?
 
Upvote 0
Yes, I'm sorry I started the post and then did something else and posted it.

I need to take the value selected from say CombBox1, and then make it the default value when the user is prompted for a filename, so they can add the job number for the filename.

Does that make sense?
 
Upvote 0
Take a look at the InitialFilename argument of GetSaveAsFilename.
Code:
Fname = Application.GetSaveAsFilename( InitialFileName = Combobox1.Value,  _ 
    FileFilter:="CSV (*.csv), *.csv")
 
Upvote 0
Norie,


Thank you so much, I am so close to having it perfect, except the Filename defaults to FALSE not what is in my combobox. Here is the code from my user form.

Code:
Private Sub ComboBox99_Change()

End Sub

Private Sub ComboBox1_Change()

End Sub

Private Sub CommandButton1_Click()
EraseData
findfile
End Sub

Private Sub CommandButton2_Click()
X
End Sub

Private Sub Image1_Click()

End Sub

Private Sub Label1_Click()

End Sub

Sub X()
    SaveAsDelimited Range("'MAS90 Data'!A1:B4"), ","
 End Sub
 
Sub SaveAsDelimited(Data As Range, Delimiter As String)
    Dim Fname As Variant
    Dim strBuf As String
    Dim rngTemp As Range
    Dim rngCell As Range
    Dim intUnit As Integer
    Dim strDelimit As String
    Dim strPath As String
    Dim strName As String
    
    MsgBox "Please enter the job number as the filename."
    Fname = Application.GetSaveAsFilename(InitialFileName = ComboBox1.Value, _
    FileFilter:="CSV (*.csv), *.csv")
    If Fname = False Then
    MsgBox "You didn't enter a filename!"
    End If
    
    intUnit = FreeFile
    Open Fname For Output As intUnit
    For Each rngTemp In Data.Rows
        strBuf = ""
        strDelimit = ""
        For Each rngCell In rngTemp.Cells
            If InStr(rngCell.Text, ",") > 0 Then
                               strBuf = strBuf & strDelimit & """" & rngCell.Text & """"
            Else
                strBuf = strBuf & strDelimit & rngCell.Text
            End If
            strDelimit = Delimiter
        Next
        Print #intUnit, strBuf
    Next
    Close intUnit
      
End Sub





Private Sub UserForm_Click()

End Sub

Any help is greatly appreciated!
 
Upvote 0
How about this...

What if I were to add a text box to my user form, and make the file name the value of ComboBox1 & TextBox1?

That would make things simpler for me and my users.

How would I get that information as the filename?

Any and all help is greatly appreciated!
 
Upvote 0
Ok, Ok, I got it now!

My filename is coming out with the initial file name of my ComboBox1.Value, now the final question is how can I get it to add to that the value of TextBox1

I really appreciate your help!

Code:
MsgBox "Please enter the job number as the filename."
    Fname = Application.GetSaveAsFilename(InitialFileName:=ComboBox1.Value, _
    FileFilter:="CSV (*.csv), *.csv")
    If Fname = False Then
    MsgBox "You didn't enter a filename!"
    End If
 
Upvote 0
Do you mean the initial filename?
Code:
 Fname = Application.GetSaveAsFilename(InitialFileName:=ComboBox1.Value & Textbox1.Value, _ 
    FileFilter:="CSV (*.csv), *.csv")
 
Upvote 0
I knew it was going to be simple!

I added an underscore to make it easier for the 3rd party program to import my file.

Code:
Fname = Application.GetSaveAsFilename(InitialFileName:=ComboBox1.Value & "_" & TextBox1.Value, _
    FileFilter:="CSV (*.csv), *.csv")

Norie,

Thank you so much for your help!


crobertson[/code]
 
Upvote 0

Forum statistics

Threads
1,203,328
Messages
6,054,754
Members
444,748
Latest member
knowak87

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