Export cells of a single column to note pad and save as a .js file using a name from another column

Last Edited By Krjb Donovan
Last Updated: Mar 05, 2014 09:35 PM GMT

QuestionEdit

What I am trying to do is to write a macro that will export each cell data from a single column to MS note pad and save it as a .js file using a name from another column. So if my table reads:

  A             B

1 Part No Java Script 2 Q2346 <all my js script... > 3 Q3452 <all my js script....>

I am trying to acheive the cell B2 as the contents sent to MS notepad and saved as Q2346.js, Q3452.js, etc.

AnswerEdit

Bill,

You didn't ask me this question. I found it in the question pool. Apparently Victor has stopped answering questions and all his pending questions were dumped in the question pool. Hopefully no misfortune has befallen Victor).

Anyway, this worked for me.

Sub WriteScripts() Dim FileNumber As Integer, FilePath As String Dim cell As Range, r As Range Dim fName As String, s As String FilePath = "D:\Data\jscripts\" With ActiveSheet Set r = .Range("A2", .Range("A2").End(xlDown)) End With For Each cell In r

 fName = FilePath & cell.Text & ".js"
 s = cell.Offset(0, 1)
 FileNumber = FreeFile

Open fName For Output As #FileNumber

 Write #FileNumber, s

Close #FileNumber Next End Sub

I don't know what your data in column B looks like, but if you want multiple lines as output you should have something like

="Command1"&char(13)&char(10)&"Command2"&Char(13)&Char(10)&"Command3"

in my testing of the macro, that would produce multiple rows of output in the .js file.

Post a followup if this is not clear or you need more explanation.

Advertisement

©2024 eLuminary LLC. All rights reserved.