+ Reply to Thread
Results 1 to 3 of 3

Macro to copy data from excel to notepad modified

Hybrid View

  1. #1
    Registered User
    Join Date
    12-17-2013
    Location
    Runcorn, England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Macro to copy data from excel to notepad modified

    Hi,
    I found a macro on your site in thread :- Macro to copy data from excel to notepad the answer was by MSP 77079 and runs well.
    I tried to alter it and have got to a point where it still runs well but I want to alter the filename and I'm coming up against Syntax errors can anyone advise please

    I added lines 5,6 & 7 and the End with from another macro, and changed the range and deleted a couple of things I didn't want.

    I want it to get it's filename from cell 92, there are 3 sheets in the Excel each with a different Cell 92 which identifies them.

    It runs perfectly but only if you have the newfile as :="C:\FName.scr", _ This saves a file called Fname.scr in the C drive and doesn't insert FName as the variable...
    So being clever and not having the faintest idea I changed it to :="C:\" & FName & ".scr", _ I got the Idea of adding & and "" from another macro but there is a syntax problem which I can't sort, can anyone put a finger on it?

    Also ideally I'd like it to save to the desktop rather than C if anyone can help Id be grateful


    Sub MakeTextFile()
    '*** change dimension to use late binding ***
    Dim FSO As Object 'FSO As Scripting.FileSystemObject
    Dim TextStr As Object 'TextStr As Scripting.TextStream
    Dim FName As String
    With ActiveSheet
    FName = .Range("A92").Value 'Get the filename from cell 92
    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:\FName.scr", _
    IOMode:=ForAppending, Create:=True)
    For Each Rng In Range("A1:A113")

    TextStr.WriteLine Text:= _
    Rng.Value

    Next Rng

    TextStr.Close
    End With
    Set FSO = Nothing

    Thanks in advance

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,062

    Re: Macro to copy data from excel to notepad modified

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Never use Merged Cells in Excel

  3. #3
    Registered User
    Join Date
    12-17-2013
    Location
    Runcorn, England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Macro to copy data from excel to notepad modified

    No problem, I've cracked it anyway...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to copy data from excel to notepad
    By emmamaki in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-19-2014, 03:42 AM
  2. how to copy selected notepad text and paste it in other notepad with macro
    By Guru232 in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 04-24-2013, 04:43 AM
  3. macro or vb Excel copy single column to notepad
    By shrinivasmj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2012, 04:05 PM
  4. [SOLVED] Copy excel data to notepad.
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2012, 08:56 AM
  5. Replies: 1
    Last Post: 02-10-2005, 06:06 PM

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