Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Help !! - Create files using VBA code

Hi

I have a file which is to be sent out to different recipients (at least
200). Although the file is same I need to send this to various
recipients with different file names. I have a list that is to be used
to name the files.
For example I have a file called Report.xls and have a list a, b,
c...z. (in a file Nemes.xls). I want a code that will save the file
report.xls as a.xls, b.xls.... z.xls in the specified folder/location.

I know this is possible using VBA code.
Can you helpme by giving some useful code?

Karthik Bhat
(Bangalore)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Help !! - Create files using VBA code

Hi there,

You could do something like the below. Note that I haven't written any
error handling, you might like to do that to make sure all of your paths
are valid. Similarly, you might want to check whether a file already
exists before saving. But this should give you the idea.

Sub GenerateNewFiles()

Dim wbReport as workbook
Dim wbNames as workbook
Dim i as Long
Const strNamesFilePath as string = "c:\temp\names.xls"

'Assuming that the active workbook is the one you
'want to create copies from
set wbReport = activeworkbook

'open up the workbook with all the names on it.
'we assume that all of the names are on the first
'sheet of the workbook thus:
' COL A COL B COL C
' Name Filename Path/Location
' Dave Myreport c:\temp
' etc.

set wbNames = workbooks.open(strNamesFilePath)

with wbNames.Sheets(1)

'go through every row in sheet 1 of the
'names workbook sheet 1

for i = 2 to .Usedrange.rows.count

'check there is a name and path
if .cells(i,2) <"" and .cells(i,3) <""
'save a copy of the report taking the
'path and filename from the worksheet
wb.Report.SaveCopyAs .cells(i,3) _
& "\" & .cells(i,2) _
& ".xls"
end if
next i
End with

End SUb

HTH,
Gareth

Karthik Bhat - Bangalore wrote:
Hi

I have a file which is to be sent out to different recipients (at least
200). Although the file is same I need to send this to various
recipients with different file names. I have a list that is to be used
to name the files.
For example I have a file called Report.xls and have a list a, b,
c...z. (in a file Nemes.xls). I want a code that will save the file
report.xls as a.xls, b.xls.... z.xls in the specified folder/location.

I know this is possible using VBA code.
Can you helpme by giving some useful code?

Karthik Bhat
(Bangalore)

  #3   Report Post  
Posted to microsoft.public.excel.programming
jai jai is offline
external usenet poster
 
Posts: 71
Default Help !! - Create files using VBA code

Hi Karthik,
The answer is to create the workbook and to use the save as option to
save it as
each name. A code snippet is attached.

Sub SaveFile()
Dim FilN As String
Dim wb As Workbook

Set wb = Workbooks.Add

do until < all names are done
FilN = {each name in turn}&".xls"}
wb.SaveAs FilN
Loop
End Sub

Hope that helps
Jai

"Karthik Bhat - Bangalore" wrote:

Hi

I have a file which is to be sent out to different recipients (at least
200). Although the file is same I need to send this to various
recipients with different file names. I have a list that is to be used
to name the files.
For example I have a file called Report.xls and have a list a, b,
c...z. (in a file Nemes.xls). I want a code that will save the file
report.xls as a.xls, b.xls.... z.xls in the specified folder/location.

I know this is possible using VBA code.
Can you helpme by giving some useful code?

Karthik Bhat
(Bangalore)


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
Testers needed for code page : create and mail PDF files in Excel 2007 with the MS PDF add-in Ron de Bruin Excel Discussion (Misc queries) 2 February 28th 09 01:37 PM
create .xlk files maryj Excel Discussion (Misc queries) 5 May 18th 07 06:10 PM
How to create a form to insert a hyerlink.VBA code to create a for karthi Excel Discussion (Misc queries) 0 July 5th 06 11:26 AM
Create a newworksheet with VBA code and put VBA code in the new worksheet module ceshelman Excel Programming 4 June 15th 05 04:37 PM
how do i create an access code sheet to number my office files an. dana New Users to Excel 1 February 12th 05 03:49 AM


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

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

About Us

"It's about Microsoft Excel"