Forum Discussion

orione1943's avatar
orione1943
Copper Contributor
Mar 04, 2022
Solved

wb.SaveAs CurrentProject.Path & nomefile

Posto il codice Private Sub Esporta_Click() Dim rs As DAO.Recordset Dim ex As Excel.Application Dim wb As Excel.Workbook Dim ws As Excel.Worksheet Dim i As Integer, PERCORSO As String, anno As ...
  • arnel_gp's avatar
    Mar 05, 2022

    orione1943 

     

    if you keep on encountering error when using SaveAs...

    you might as well revised the step of Creating workbook from your Template:

     

    1. Create the "work" workbook from your template first:

     

    VBA.FileCopy CurrentProject.Path & "\modello DDT.xlsx",  CurrentProject.Path & "\" & nomefile

     

    now directly open the nomefile and update it:

     

    Set wb = ex.Workbooks.Open(CurrentProject.Path & "\" & nomefile)
    'seleziona il foglio 1
    Set ws = wb.Worksheets("RIGHE DOCUMENTO")

    'rest of code here

    ...

    ...

    'Close and Save changes

    wb.Close, True

     

     

     

     

Resources