+ Reply to Thread
Results 1 to 12 of 12

copying data from excel into notepad

  1. #1
    Forum Contributor
    Join Date
    12-09-2006
    Posts
    229

    copying data from excel into notepad

    I am trying to copy data from an excel sheet and I want to paste it into note pad and save it on c drive. Is there a way to write a macro to do that task? Basically copy the data from excel, then open notepad and paste it there, save the notepad in txt extension on the hard drive.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Does this link help

    http://www.excelforum.com/showthread...26#post1738026

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Contributor
    Join Date
    12-09-2006
    Posts
    229

    Smile

    Thanks it worked fine but if I want to use this script on different computer but it does not have the same reference lib. How can I use it?

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Did you try MSP77079 code

    e.g replace the non ' code with the ' code for all lines

    Please Login or Register  to view this content.
    for

    Please Login or Register  to view this content.
    VBA Noob

  5. #5
    Forum Contributor
    Join Date
    12-09-2006
    Posts
    229
    the only think I changes is this and the reference library error still coming up.

    Sub MakeTextFile()

    '*** change dimension to use late binding ***
    Dim FSO As Scripting.FileSystemObject
    Dim TextStr As Object 'TextStr As Scripting.TextStream

    Dim Rng As Range

    '*** use create object to create a FileSystemObject ***
    'Set FSO = New Scripting.FileSystemObject
    Set FSO = CreateObject("Scripting.FileSystemObject")

    '*** Open a text file for appending ***
    '*** if it does not already exist, then create it ***
    ForAppending = 8
    Set TextStr = FSO.OpenTextFile(Filename:="C:\MyFile.txt", _
    IOMode:=ForAppending, create:=True)

    For Each Rng In Range("A1:A10")
    If Rng.Value <> "" Then
    TextStr.WriteLine Text:="The Value In: " & _
    Rng.Address(False, False) & " is: " & Rng.Value
    End If
    Next Rng


    TextStr.Close
    Set FSO = Nothing


    End Sub

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Change all ' strings

    VBA Noob

  7. #7
    Forum Contributor
    Join Date
    12-09-2006
    Posts
    229
    I am not sure what you mean by Change all strings the actual code that I use is below.

    '*** change dimension to use late binding ***
    Dim FSO As Scripting.FileSystemObject
    Dim TextStr As Scripting.TextStream
    Dim Rng As Range

    '*** use create object to create a FileSystemObject ***
    'Set FSO = New Scripting.FileSystemObject
    Set FSO = CreateObject("Scripting.FileSystemObject")

    '*** Open a text file for appending ***
    '*** if it does not already exist, then create it ***
    ForAppending = 8
    Set TextStr = FSO.OpenTextFile(Filename:=SheetName & ".kml", _
    IOMode:=ForAppending, create:=True)
    ActiveWorkbook.Worksheets("Output").Activate
    For Each Rng In Range("A1:A65000")
    If Rng.Value <> "" Then
    TextStr.WriteLine Text:=Rng.Value
    End If
    Next Rng

    TextStr.Close
    Set FSO = Nothing

  8. #8
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Try

    Please Login or Register  to view this content.
    VBA Noob

  9. #9
    Forum Contributor
    Join Date
    12-09-2006
    Posts
    229
    still getting the error "Can't Find project Library"
    I updated my code to reflect what you have

    '*** change dimension to use late binding ***
    Dim FSO As Scripting.FileSystemObject
    Dim TextStr As Scripting.TextStream
    Dim Rng As Range

    '*** use create object to create a FileSystemObject ***
    Set FSO = New Scripting.FileSystemObject

    '*** Open a text file for appending ***
    '*** if it does not already exist, then create it ***
    ForAppending = 8
    Set TextStr = FSO.OpenTextFile(Filename:=SheetName & ".kml", _
    IOMode:=ForAppending, create:=True)
    ActiveWorkbook.Worksheets("Output").Activate
    For Each Rng In Range("A1:A65000")
    If Rng.Value <> "" Then
    TextStr.WriteLine Text:=Rng.Value
    End If
    Next Rng

    TextStr.Close
    Set FSO = Nothing

  10. #10
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Does this help

    http://support.microsoft.com/kb/213524


    VBA Noob

  11. #11
    Forum Contributor
    Join Date
    12-09-2006
    Posts
    229
    Thank you so much for all your help. The script works really well.

  12. #12
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Glad you got it sorted

    VBA Noob

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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