Solved

Script or similar to create hundreds of cutomised Excel files

Posted on 2013-12-17
7
139 Views
Last Modified: 2013-12-19
I need to create several hundred customised Excel files.

I have a template file with a bunch of field names as the first row. The second row is to be filled in by the recipient.

I have a master file with two columns which contains the name I want for each file, which is a number, like 92625785965 (an ABN, in fact) and a Company Name.

The company name needs to go into cell A2.

How can I go about this in an automated fashion?
0
Comment
Question by:snooflehammer
  • 4
  • 3
7 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39725853
You would need a macro like this

sub generatefiles
dim sws as worksheet
dim mws as worksheet
dim cel as range
set sws=activeworksheet
set mws = workbooks("masterworkbook.xls")
for each cel in mws.range("A1:A1000")
if cel<>"" then
sws.copy
activesheet.range("A2").value=cel.offset(,1)
activeworkbook.saveas cel.value & ".xlsx"
activeworkbook.close
end if
next cel
0
 

Author Comment

by:snooflehammer
ID: 39725863
This is a macro I run from within an Excel workbook?
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39725865
Yes, I would do it from the template workbook.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:snooflehammer
ID: 39725971
OK. I'll get to try this out in the next 48 hours. I'll revert then
0
 

Author Comment

by:snooflehammer
ID: 39727812
I'm struggling with this.

I\ve saved a worksheet with the filenames in colum 1 and the company names in column 2. Its called Book1.xlsx and it's on my D drive, so its full path is D:\Book1.xlsx.

The macro crashes on line 5 with run-time error '424'. Object required.

I've tried entering the path to book1, but no dice.
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 39728267
Sorry, change it to

set sws=activesheet
0
 

Author Closing Comment

by:snooflehammer
ID: 39730189
Thank you
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question