Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Big Ian
 
Posts: n/a
Default How to use this subroutine on multiple cells?

Hi,

I have the following routine that makes text in cell A1 into the contents of
a file defined by B1 and C1.

-------------------------------------------------------
Sub WriteCellToFile()
Dim fso As Object
Dim ts As Object
Dim strCellContents As String
Dim strFileName As String
Dim strPath As String

strCellContents = Range("A1").Text
strFileName = Range("B1").Text
strPath = Range("C1").Text

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile(strPath & strFileName, True)
ts.writeline (strCellContents)
ts.Close

End Sub
-------------------------------------------------------

I tried running it with Run-Sub/User Form but I can only get it to work on
one line, if I change the range to A1:A10 I get an error. Can anybody tell me
how to make it into a macro that writes all cells in column A to files?


Thanks,
Ian
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob Phillips
 
Posts: n/a
Default How to use this subroutine on multiple cells?

Sub WriteCellToFile()
Dim fso As Object
Dim ts As Object
Dim strCellContents As String
Dim strFileName As String
Dim strPath As String
Dim cell As Range

Set fso = CreateObject("Scripting.FileSystemObject")

For Each cell In Range("A1:A10")
strCellContents = cell.Text
strFileName = cell.Text
strPath = cell.Text
Set ts = fso.CreateTextFile(strPath & strFileName, True)
ts.writeline (strCellContents)
ts.Close
Next cell

Set ts = Nothing
Set fso = Nothing

End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Big Ian" <Big wrote in message
...
Hi,

I have the following routine that makes text in cell A1 into the contents

of
a file defined by B1 and C1.

-------------------------------------------------------
Sub WriteCellToFile()
Dim fso As Object
Dim ts As Object
Dim strCellContents As String
Dim strFileName As String
Dim strPath As String

strCellContents = Range("A1").Text
strFileName = Range("B1").Text
strPath = Range("C1").Text

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile(strPath & strFileName, True)
ts.writeline (strCellContents)
ts.Close

End Sub
-------------------------------------------------------

I tried running it with Run-Sub/User Form but I can only get it to work on
one line, if I change the range to A1:A10 I get an error. Can anybody tell

me
how to make it into a macro that writes all cells in column A to files?


Thanks,
Ian



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Big Ian
 
Posts: n/a
Default How to use this subroutine on multiple cells?

Hi Bob,

Thanks for your help. I tried to run the routine but I got an error on line:

Set ts = fso.CreateTextFile(strPath & strFileName, True)

Run-time error '76'
Path not found

Also, I need each line to create a different file. The files are defined in
columns B and C, B is the name and C is the path.

Ian


"Bob Phillips" wrote:

Sub WriteCellToFile()
Dim fso As Object
Dim ts As Object
Dim strCellContents As String
Dim strFileName As String
Dim strPath As String
Dim cell As Range

Set fso = CreateObject("Scripting.FileSystemObject")

For Each cell In Range("A1:A10")
strCellContents = cell.Text
strFileName = cell.Text
strPath = cell.Text
Set ts = fso.CreateTextFile(strPath & strFileName, True)
ts.writeline (strCellContents)
ts.Close
Next cell

Set ts = Nothing
Set fso = Nothing

End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Big Ian" <Big wrote in message
...
Hi,

I have the following routine that makes text in cell A1 into the contents

of
a file defined by B1 and C1.

-------------------------------------------------------
Sub WriteCellToFile()
Dim fso As Object
Dim ts As Object
Dim strCellContents As String
Dim strFileName As String
Dim strPath As String

strCellContents = Range("A1").Text
strFileName = Range("B1").Text
strPath = Range("C1").Text

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile(strPath & strFileName, True)
ts.writeline (strCellContents)
ts.Close

End Sub
-------------------------------------------------------

I tried running it with Run-Sub/User Form but I can only get it to work on
one line, if I change the range to A1:A10 I get an error. Can anybody tell

me
how to make it into a macro that writes all cells in column A to files?


Thanks,
Ian




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob Phillips
 
Posts: n/a
Default How to use this subroutine on multiple cells?

Sorry, forgot my offsets. Try this

Sub WriteCellToFile()
Dim fso As Object
Dim ts As Object
Dim strCellContents As String
Dim strFileName As String
Dim strPath As String
Dim cell As Range

Set fso = CreateObject("Scripting.FileSystemObject")

For Each cell In Range("A1:A10")
strCellContents = cell.Text
strFileName = cell.Offset(0, 1).Text
strPath = cell.Offset(0, 2).Text
Set ts = fso.CreateTextFile(strPath & strFileName, True)
ts.writeline (strCellContents)
ts.Close
Next cell

Set ts = Nothing
Set fso = Nothing

End Sub



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Big Ian" wrote in message
...
Hi Bob,

Thanks for your help. I tried to run the routine but I got an error on

line:

Set ts = fso.CreateTextFile(strPath & strFileName, True)

Run-time error '76'
Path not found

Also, I need each line to create a different file. The files are defined

in
columns B and C, B is the name and C is the path.

Ian


"Bob Phillips" wrote:

Sub WriteCellToFile()
Dim fso As Object
Dim ts As Object
Dim strCellContents As String
Dim strFileName As String
Dim strPath As String
Dim cell As Range

Set fso = CreateObject("Scripting.FileSystemObject")

For Each cell In Range("A1:A10")
strCellContents = cell.Text
strFileName = cell.Text
strPath = cell.Text
Set ts = fso.CreateTextFile(strPath & strFileName, True)
ts.writeline (strCellContents)
ts.Close
Next cell

Set ts = Nothing
Set fso = Nothing

End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Big Ian" <Big wrote in message
...
Hi,

I have the following routine that makes text in cell A1 into the

contents
of
a file defined by B1 and C1.

-------------------------------------------------------
Sub WriteCellToFile()
Dim fso As Object
Dim ts As Object
Dim strCellContents As String
Dim strFileName As String
Dim strPath As String

strCellContents = Range("A1").Text
strFileName = Range("B1").Text
strPath = Range("C1").Text

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile(strPath & strFileName, True)
ts.writeline (strCellContents)
ts.Close

End Sub
-------------------------------------------------------

I tried running it with Run-Sub/User Form but I can only get it to

work on
one line, if I change the range to A1:A10 I get an error. Can anybody

tell
me
how to make it into a macro that writes all cells in column A to

files?


Thanks,
Ian






  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Big Ian
 
Posts: n/a
Default How to use this subroutine on multiple cells?

Bob you're a legend! Many thanks again.

Ian


"Bob Phillips" wrote:

Sorry, forgot my offsets. Try this

Sub WriteCellToFile()
Dim fso As Object
Dim ts As Object
Dim strCellContents As String
Dim strFileName As String
Dim strPath As String
Dim cell As Range

Set fso = CreateObject("Scripting.FileSystemObject")

For Each cell In Range("A1:A10")
strCellContents = cell.Text
strFileName = cell.Offset(0, 1).Text
strPath = cell.Offset(0, 2).Text
Set ts = fso.CreateTextFile(strPath & strFileName, True)
ts.writeline (strCellContents)
ts.Close
Next cell

Set ts = Nothing
Set fso = Nothing

End Sub



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Big Ian" wrote in message
...
Hi Bob,

Thanks for your help. I tried to run the routine but I got an error on

line:

Set ts = fso.CreateTextFile(strPath & strFileName, True)

Run-time error '76'
Path not found

Also, I need each line to create a different file. The files are defined

in
columns B and C, B is the name and C is the path.

Ian


"Bob Phillips" wrote:

Sub WriteCellToFile()
Dim fso As Object
Dim ts As Object
Dim strCellContents As String
Dim strFileName As String
Dim strPath As String
Dim cell As Range

Set fso = CreateObject("Scripting.FileSystemObject")

For Each cell In Range("A1:A10")
strCellContents = cell.Text
strFileName = cell.Text
strPath = cell.Text
Set ts = fso.CreateTextFile(strPath & strFileName, True)
ts.writeline (strCellContents)
ts.Close
Next cell

Set ts = Nothing
Set fso = Nothing

End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Big Ian" <Big wrote in message
...
Hi,

I have the following routine that makes text in cell A1 into the

contents
of
a file defined by B1 and C1.

-------------------------------------------------------
Sub WriteCellToFile()
Dim fso As Object
Dim ts As Object
Dim strCellContents As String
Dim strFileName As String
Dim strPath As String

strCellContents = Range("A1").Text
strFileName = Range("B1").Text
strPath = Range("C1").Text

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile(strPath & strFileName, True)
ts.writeline (strCellContents)
ts.Close

End Sub
-------------------------------------------------------

I tried running it with Run-Sub/User Form but I can only get it to

work on
one line, if I change the range to A1:A10 I get an error. Can anybody

tell
me
how to make it into a macro that writes all cells in column A to

files?


Thanks,
Ian






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find multiple cells/replace whole cells w/data dcurylo Excel Discussion (Misc queries) 2 November 30th 05 08:06 PM
How do I merge cells with multiple data values? KatMic Excel Discussion (Misc queries) 2 November 28th 05 10:13 PM
how can i ignore blank cells when multiple cells? arash Excel Worksheet Functions 4 November 17th 05 04:35 PM
How do I insert a symbol BEFORE text for multiple cells in Excel? amspalinger Excel Worksheet Functions 6 May 17th 05 07:26 PM
how do i add the same text after current text in multiple cells Sue Excel Discussion (Misc queries) 3 January 13th 05 09:28 PM


All times are GMT +1. The time now is 10:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"