Saved Worksheet looks like garbage/New problem
Hello,
I attempt to save a Worksheet to the Users PC using the following code (commented out stuff to get the bare-boned code to work), but the output looks like garbage. This is an Excel/VBA app run on a web server, and this button is on a UserForm.
VB Code:
Private Sub cmdSave_Click()
Dim varFileName As Variant
Dim NumRows As Long, NumCols As Integer
Dim r As Long, c As Integer
Dim data
On Error GoTo 300
NumCols = Columns.Count
NumRows = Rows.Count
ChDir "C:\"
varFileName = Application.GetSaveAsFilename("MyReport.txt", "Text Files (*.txt),*.txt," & _
"Print Files(*.prn),*.prn", 1, "MyReport")
If (VarType(varFileName) = vbString) Then
Open varFileName For Output As #1
' For r = 1 To NumRows
' For c = 1 To NumCols
' data = Cells(r, c).Value
' If c <> NumCols Then
Print #1, data;
' Else
' Print #1, data
' End If
' Next c
' Next r
Close #1
ActiveWorkbook.SaveAs FileName:=varFileName
Exit Sub
300:
MsgBox Err.Number & " " & Err.Description
Resume Next
End If
End Sub
When the User clicks a button, they should be prompted as to where to save the file (this works fine) then I have to save it there.
Should the line that says, "ActiveWorkbook.SaveAs etc." be "ActiveWorkbook("Worksheet Name").SaveAs etc." ?
Thank you for any help,
CJ