?
Solved

Open and save existing Excel file

Posted on 2003-03-24
4
Medium Priority
?
363 Views
Last Modified: 2010-04-07
VB6 : I 'm looking for a manner to open an existing Excelfile (with a certain lay-out) and then save it under another name. I have to put the records from a recordset in such a file. The difficult part is to save the file while I have always problems with closing the original file and reopening it for new edit. (Each recordline in my recordset must be a new saved file.)
Please find below my code :
 
    For i = 1 To 30
        vRsDepenses.Filter = "Magasin_id = " & i
        If vRsDepenses.RecordCount > 0 Then
            Set objExcel = New Excel.Application
            objExcel.Visible = False
            objExcel.Workbooks.Open ("C:\Program Files\Club\Report.xls")

           With objExcel.Sheets("Caisse")
                'Header
                .Cells(1, 1).Value = "JHKIHFccG"
                'columns
                .Cells(1, j).Value = vRsDepenses.Fields("Date_Depenses")
                .Cells(3, j).Value = vRsDepenses.Fields("Cash")
                ' ...
           End With
            vRsDepenses.MoveNext
           
            Loop
            'Close and save Excel File
            objExcel.SaveWorkspace ("C:\Program Files\Club\Reports\KRC" & vRsRecettes.Fields("magasin_id") & ".xls")
            objExcel.Workbooks.Close
            Set objExcel = Nothing
            'DoEvents
        End If
        pFrm("ProgressBar1").Value = i
    Next i


0
Comment
Question by:claesk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 280 total points
ID: 8193669
Hello claesk,

you could try to change the save workspace to
objExcel.ActiveWorkbook.SaveAs ("C:\Program Files\Club\Reports\KRC" & vRsRecettes.Fields("magasin_id") & ".xls")

HAGD:O)Bruintje
0
 

Author Comment

by:claesk
ID: 8193711
Thanks for the quick answer. This seems to work.
Kind regards / vriendelijke groeten,
K.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 8193718
:) you're welcome / tot uw dienst
B
0
 

Author Comment

by:claesk
ID: 8193726
:-)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 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