breakhappy
New Member
- Joined
- Jun 30, 2008
- Messages
- 22
First off, I would like to say that I am not an experienced programmer and am just learning VB. I have no training and just try to strong together code based on logic. Most of what I've learned so far has been from forums like this one and am hoping someone here can help me. I appreciate any advice or help anyone can give me...
Based on the selection of radio buttons on a userform I created, I am looking for a sub that will 'Save As', as a different file type. Let me first describe the userform objects and then what I am trying to do.
The userform will be used for exporting data from one worksheet to another. The userform has 3 radio buttons to allow the user to save the data in different file formats. The first - .dbf format, the second - .txt format, the third - .csv format. The userform also has a textbox that allows the user to enter a name in which they would like the exported file to be named.
I am trying to string together a macro that will:
1. Identify which radio button the user has selected
2. Take the text that the user has filled in the userbox (show msgbox error if no text has been entered) and save the file as the appropriate file format type, based on which radio button has been selected.
This is the code that I had but it doesn't seem to be working (Ignore it if you think I'm going about it all wrong).
Based on the selection of radio buttons on a userform I created, I am looking for a sub that will 'Save As', as a different file type. Let me first describe the userform objects and then what I am trying to do.
The userform will be used for exporting data from one worksheet to another. The userform has 3 radio buttons to allow the user to save the data in different file formats. The first - .dbf format, the second - .txt format, the third - .csv format. The userform also has a textbox that allows the user to enter a name in which they would like the exported file to be named.
I am trying to string together a macro that will:
1. Identify which radio button the user has selected
2. Take the text that the user has filled in the userbox (show msgbox error if no text has been entered) and save the file as the appropriate file format type, based on which radio button has been selected.
This is the code that I had but it doesn't seem to be working (Ignore it if you think I'm going about it all wrong).
Code:
Sub SaveAsCell()
Dim strName As String
On Error GoTo InvalidName
If DBFOptionButton = True Then
strName = SaveFileName.Value & Sheet5.Range("E2")
ActiveWorkbook.SaveAs strName
FileFormat = xlDBF4
Else
GoTo Next_Button
Next_Button:
If ASCIIOptionButton = True Then
strName = SaveFileName.Value & Sheet5.Range("E3")
ActiveWorkbook.SaveAs strName
FileFormat = xlText
Else
GoTo Next_Button2
Next_Button2:
If CommaOptionButton = True Then
strName = SaveFileName.Value & Sheet5.Range("E2")
ActiveWorkbook.SaveAs strName
FileFormat = xlCSV
Else
GoTo InvalidName
End If
Exit Sub
InvalidName: MsgBox "The text: " & strName & _
" is not a valid file name."
End Sub [\code]
The error code that I recieve is: "Compile error: Block If without End If". Can anyone help?