• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

Open and save existing Excel file

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
claesk
Asked:
claesk
  • 2
  • 2
1 Solution
 
bruintjeCommented:
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
 
claeskAuthor Commented:
Thanks for the quick answer. This seems to work.
Kind regards / vriendelijke groeten,
K.
0
 
bruintjeCommented:
:) you're welcome / tot uw dienst
B
0
 
claeskAuthor Commented:
:-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now