+ Reply to Thread
Results 1 to 3 of 3

Copy selection and save as a .bat file

Hybrid View

  1. #1
    Registered User
    Join Date
    12-24-2010
    Location
    WV
    MS-Off Ver
    Excel 2003
    Posts
    8

    Copy selection and save as a .bat file

    Hi guys,
    Hoping someone can help me with this. I am needing to get some codes from Excel in several rows and save that as a batch file. Below is what I have so far. I need to be able to copy the selection put it in text file and save as file.bat format.

    Sub MakeRows()

    ' Find the last row of data

    LastRow = Range("A65536").End(xlUp).Row


    ' Autofill the formula for each row of HTAG numbers

    Range("B1").Select
    Selection.AutoFill Destination:=Range("B1:B" & LastRow)
    ' Selects the range of rows
    Range("B1:B" & LastRow).Select

    ***I need to save this in a file called file.bat***


    End Sub

    I greatly appreciate any help you can give me.

    Thanks

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copy selection and save as a .bat file

    Sub MakeRows()
        
        Dim FF As Integer, cell As Range
        Dim srtPath As String, strFile As String
        
        strPath = "C:\"         'File path
        strFile = "File.bat"    'File name
        
        With Range("B1", Range("A65536").End(xlUp).Offset(, 1))
            ' Autofill the formula for each row of HTAG numbers
            Range("B1").AutoFill Destination:=.Cells
            'Write Values to text file
            FF = FreeFile()
            Open strPath & strFile For Output As #FF
            For Each cell In .Cells
                Print #FF, cell.Text
            Next cell
            Close #FF
        End With
        
        MsgBox strPath & strFile, vbInformation, "HTAG Text Saved"
        
    End Sub

  3. #3
    Registered User
    Join Date
    12-24-2010
    Location
    WV
    MS-Off Ver
    Excel 2003
    Posts
    8

    [Solved] Re: Copy selection and save as a .bat file

    AlphaFrog,
    You are a lifesaver. This worked like a charm and I am grateful to you. You have no idea how much easier this makes my life. Thank you so much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1