VBA Exporting to text file

5 pts.
Tags:
Microsoft Excel
VBA
I am trying to make a VBA to copy multiple cells from excel to notepad in this sort of format:
Interface GigabitEthernet1/0/1

Switchport access vlan 990

shut
But all I seem to be doing is copying the top line over and over again. Here's the code I've been using:
Sub exprtToText()
Dim ff As Long, lRow As Long

' name of your sheet, you may change it if needed
Const NameOfTheSheet As String = "Sheet1"

' update to the folder path, make sure it ends with 
Const sTextTileDirectoryPath As String = "C:Usersz003acxrDesktop"
Const NameOfFile As String = "GeneratedConfig"

ff = VBA.FreeFile

With ThisWorkbook.Sheets(NameOfTheSheet)
    'lRow = .Range("N" & Rows.Count).End(xlUp).Row

    Open sTextTileDirectoryPath & NameOfFile & ".txt" For Output Access Write As #ff
        'Print #ff, Join(Evaluate(Replace(Replace("transpose(#N1:N@)", "#", "'" & NameOfTheSheet & "'!"), "@", lRow)), vbNewLine)
        
        'Print #ff, (.Range("N1") & vbCrLf & .Range("O1") & .Range("Q1") & .Range("R1") & .Range("T1"))
        For Count = 0 To 10
Print #ff, (.Range("N1") & .Range("O1") & vbCrLf & .Range("Q1") & .Range("R1") & vbCrLf & .Range("T1"))
            
        Next Count

        
    Close #ff
End With

MsgBox "Text File Created", vbInformation
End Sub
Ideally I'd like it to run to the end of the list but have not figured out how to get that far. Any ideas? Cheers Matt
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: