GetSaveAsFilename

O

Oswlad

Can anyone advise me a method to divert/re-program the 'Save' button
on the GetSaveAsFilename dialog to run my own comma delimited file
saving routine, I need to save specific areas of text values and
formulas from an Excel 2000 worksheet in XP, or will I need to
recreate a facsimile of the file SaveAs form.

Thanks for any help
Oswald
 
W

Wouter HM

Hi Oswald

In Excel 2003 I created the code below.
As far as I know there are no changes in the VBA between 2002 and
2003.

Sub OswladSave()
Dim strFilename As String
Dim lngRow As Long
Dim lngCol As Long
Dim lngFree As Long
Dim strRow As String

strFilename = Application.GetSaveAsFilename

' When cancel is clikced
If strFilename = "False" Then Exit Sub

lngFree = FreeFile

Open strFilename For Output As lngFree

For lngRow = 1 To Selection.Rows.Count
strRow = ""
For lngCol = 1 To Selection.Columns.Count
If lngCol > 1 Then
strRow = strRow & ","
End If
strRow = strRow & _
CStr(Selection.Cells(lngRow, lngCol).Value)

Next
Print #lngFree, strRow
Next

Close #lngFree
End Sub

HTH,

Wouter
 
O

Oswlad

HiOswald

In Excel 2003 I created the code below.
As far as I know there are no changes in the VBA between 2002 and
2003.

Sub OswladSave()
    Dim strFilename As String
    Dim lngRow As Long
    Dim lngCol As Long
    Dim lngFree As Long
    Dim strRow As String

    strFilename = Application.GetSaveAsFilename

    ' When cancel is clikced
    If strFilename = "False" Then Exit Sub

    lngFree = FreeFile

    Open strFilename For Output As lngFree

    For lngRow = 1 To Selection.Rows.Count
        strRow = ""
        For lngCol = 1 To Selection.Columns.Count
            If lngCol > 1 Then
                strRow = strRow & ","
            End If
            strRow = strRow & _
                          CStr(Selection.Cells(lngRow, lngCol).Value)

        Next
        Print #lngFree, strRow
    Next

    Close #lngFree
End Sub

HTH,

Wouter

Wouter you are a gem, thank you very much, your code has the simple
elegance I was looking for, this isn't commercial but I will honour
you as the core donor in my VB code.

Oswald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top