Results 1 to 9 of 9

Thread: Saved Worksheet looks like garbage/New problem

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257

    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:
    1. Private Sub cmdSave_Click()
    2. Dim varFileName As Variant
    3. Dim NumRows As Long, NumCols As Integer
    4. Dim r As Long, c As Integer
    5. Dim data
    6.  
    7. On Error GoTo 300
    8. NumCols = Columns.Count
    9. NumRows = Rows.Count
    10. ChDir "C:\"
    11. varFileName = Application.GetSaveAsFilename("MyReport.txt", "Text Files (*.txt),*.txt," & _
    12. "Print Files(*.prn),*.prn", 1, "MyReport")
    13. If (VarType(varFileName) = vbString) Then
    14.  
    15. Open varFileName For Output As #1
    16. ' For r = 1 To NumRows
    17. '  For c = 1 To NumCols
    18. '  data = Cells(r, c).Value
    19. '  If c <> NumCols Then
    20.    Print #1, data;
    21. '  Else
    22. '   Print #1, data
    23. '  End If
    24. '  Next c
    25. ' Next r
    26. Close #1
    27.  
    28. ActiveWorkbook.SaveAs FileName:=varFileName
    29. Exit Sub
    30. 300:
    31. MsgBox Err.Number & " " & Err.Description
    32. Resume Next
    33. End If
    34. 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
    Last edited by CyberJar; Apr 6th, 2004 at 07:10 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width