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
Bookmarks