Reputation: 48
I found relevent things but not the exact match and I don't know how fix them.
I have an excel file with only 1 row(with many columns) and 1 column (with many rows).
Now I would like to use vba and create files from all the rows of 1st column and , put the same data (i.e. cloumn b to infinty of 1st row) inside all the files.
Just an example:
excel file:
a 2 3 4
b
c
files would be:
a.php, b.php, c.php
with same data inside them:
2 3 4
Thanks in advance
Upvotes: 0
Views: 87
Reputation: 22175
While the rationale for doing this to generate web content eludes me, this is trivial to do. Just loop through the 1st row to get the data, then loop through the first column to get the filenames and output copies:
Const path = "C:\YourDestinationDirectory\"
Public Sub DumpPHP()
Dim sheet As Worksheet
Dim data As String
Dim index As Long
Set sheet = ActiveSheet
For index = 2 To sheet.UsedRange.Columns.Count
data = data & sheet.Cells(1, index)
Next index
Dim handle As Integer
For index = 2 To sheet.UsedRange.Rows.Count
handle = FreeFile
Open path & sheet.Cells(index, 1) & ".php" For Output As #handle
Print #handle, data
Close #handle
Next index
End Sub
Upvotes: 0