473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Creating a loop to save multiple excel documents...

cori25
83
Hello...

I am attempting to open up 4 paths and then save each path using a loop.

[PHP]Option Compare Database
Function SaveSat()

Dim strMonth As String

Dim strSavePath(4) As String

Dim strPath(4) As String


strPath(0) = "C:\Database\Daily_Ourvoice\Data\180\Sat.xls"
strPath(1) = "C:\Database\Daily_Ourvoice\Data\181\Sat.xls"
strPath(2) = "C:\Database\Daily_Ourvoice\Data\182\Sat.xls"
strPath(3) = "C:\Database\Daily_Ourvoice\Data\183\Sat.xls"
strPath(4) = "C:\Database\Daily_Ourvoice\Data\184\Sat.xls"

Dim xlApp As New Excel.Application
xlApp.Workbooks.Open filename:="" & strPath & ""
xlApp.Visible = True

DoCmd.SetWarnings False

strMonth = Format(Date, "mm-dd-yyyy")

For i = 0 To 4

strSavePath(0) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(180)(" & strMonth & ").xls"
strSavePath(1) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(181)(" & strMonth & ").xls"
strSavePath(2) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(182)(" & strMonth & ").xls"
strSavePath(3) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(183)(" & strMonth & ").xls"
strSavePath(4) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(184)(" & strMonth & ").xls"

xlApp.ActiveWorkbook.SaveAs strSavePath

Next
xlApp.Quit
Set xlApp = Nothing
End Function[/PHP]

I can not get this to work and need it asap. Any help appreciated..

Thanks
Mar 5 '08 #1
3 2599
Denburt
1,356 Expert 1GB
For i = 0 To 4

strSavePath(0) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(180)(" & strMonth & ").xls"
strSavePath(1) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(181)(" & strMonth & ").xls"
strSavePath(2) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(182)(" & strMonth & ").xls"
strSavePath(3) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(183)(" & strMonth & ").xls"
strSavePath(4) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(184)(" & strMonth & ").xls"

xlApp.ActiveWorkbook.SaveAs strSavePath

Next
Thanks
I see a number of issues with this procedure, one that hit me right off was what I quoted above. try something like the following or just remove the for each statement in the quote above. You should also turn your warnings back on at the end of the procedure and it should work.
Expand|Select|Wrap|Line Numbers
  1. For i = 0 To 4
  2. strSavePath(i) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(180)(" & strMonth & ").xls"
  3. xlApp.ActiveWorkbook.SaveAs strSavePath
  4. Next
  5. DoCmd.SetWarnings True
  6.  
Mar 5 '08 #2
cori25
83
This would work if the strSavePath were the same for all documents. If you look closely each savepath is different and I need the strpath to open and then save then go to the next strpath, open and save....
Mar 6 '08 #3
Denburt
1,356 Expert 1GB
Yeah what was I thinking. Try the following:

Expand|Select|Wrap|Line Numbers
  1. strSavePath(0) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(180)(" & strMonth & ").xls"
  2. strSavePath(1) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(181)(" & strMonth & ").xls"
  3. strSavePath(2) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(182)(" & strMonth & ").xls"
  4. strSavePath(3) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(183)(" & strMonth & ").xls"
  5. strSavePath(4) = "\\Norwalk2\COMMON1\Field Ops\DailyOurVoice_BackUps\Sat(184)(" & strMonth & ").xls"
  6. For i = 0 To 4
  7. xlApp.ActiveWorkbook.SaveAs strSavePath(i)
  8. Next
  9. xlApp.Quit
  10. DoCmd.SetWarnings False
  11. Set xlApp = Nothing
  12. End Function
Mar 6 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: tim.tadh | last post by:
Hi I am writing a program that allows a user to annotate text documents, and later html, html variants, and PDF files. My program is able to load multiple documents at once and creat linked...
5
by: Guy Incognito | last post by:
Hello, I've written an asp.net application that creates Excel documents. It works by creating an excel document in XML format. But I wonder if I'm reinventing the wheel. I know that there are...
2
by: JBAdamsJr | last post by:
I want to be able to create an Excel file with a VB.NET program on a server that does not have Microsoft Excel loaded on it. I am using the Jet OLE DB to read other data files. Can this be used to...
9
by: Paul | last post by:
Hi all Arggghhh........... The problem.....I want the user to be able to create an excel document and name particular cells in the document where they want the data to be placed and then save...
5
by: Carl | last post by:
Please can anyone tell me how I can create a macro to save the results of a query as an excel file? The query is called Student List and I would like to save it to "My Documents". We have had...
0
by: volume | last post by:
Hi all, In an effort to try to impress the boss, I would like to log accounting information to an Excel spreadsheet using C# and .NET. This would be a mockup only, not a real solution - yet! We...
1
by: rkgarnepudi | last post by:
Hi there We have content delivery web site embedded with MSOffice documents like (MS-word, Excel, powerpoint, pdf) for users. The problems we are facing is specified below..... 1. We are not...
3
by: evenlater | last post by:
I have an Access application on a terminal server. Sometimes my users need to export reports to pdf, rtf or xls files and save them to their own client device hard drives. They can do that right...
0
Pittaman
by: Pittaman | last post by:
Hello, We're developing an application (.NET 2.0) that let's users drop documents in the application and allows users to show some document types "embedded". For example, a textfile would appear...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.