View Single Post
 
Old 05-09-2017, 01:11 PM
nospamdav999 nospamdav999 is offline Windows 10 Office 2016
Novice
 
Join Date: Apr 2017
Posts: 4
nospamdav999 is on a distinguished road
Question Save an excel file with a macro ?

Hello everybody,

i have a question, about an excel file, i use a macro to generate files and initially i used to print directly these files, but now i would like to save each file.

My problem, it's working when i use "xlOpenXMLWorkbookMacroEnabled" as the fileformat option, it works like that, but what i would like is to just save the workbook, without the macro, so i have tried with this fileformat "xlOpenXMLWorkbook", but it dosen't work, because i get an error like excel can't save in this format, would you do ...blabla, it's annoying for a macro which should generate the file automatically isn't it ?

Can somebody helps me on this topic ?

I use a workbook, with a table to copy/paste the "variables", and my sheet on the second workbook.

Below i paste my macro :
Code:
Option Explicit    Sub publipostage()  Dim newWst As Worksheet, curCell As Range  Dim File As String  Set curCell = ThisWorkbook.Sheets("Feuil1").Range("A6")    'créer une nouvelle feuille  ThisWorkbook.Worksheets("Feuil4").Copy after:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)  Set newWst = ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)  'supprimer le bouton de la feuille  'newWst.Shapes("Rectangle 1").Delete    'boucle sur les entrées de la Feuil1  While curCell.Value <> vbNullString      With newWst          'copier les valeurs          .Range("I8").Value = curCell.Value          .Range("F9").Value = curCell.Offset(0, 2).Value          .Range("R9").Value = curCell.Offset(0, 3).Value          .Range("R8").Value = curCell.Offset(0, 5).Value          .Range("I6").Value = curCell.Offset(0, 9).Value          .Range("P13").Value = curCell.Offset(0, 12).Value          .Range("R6").Value = curCell.Offset(0, 10).Value          .Range("R7").Value = curCell.Offset(0, 11).Value          'impripmer la feuille (printout) ou la sauvegarder (saveas)          On Error Resume Next          '.PrintOut          File = ActiveWorkbook.Path & "\TEST" & curCell.Offset(0, 13).Value & ".xlsm"          'File = "C:\TEST" & curCell.Offset(0, 13).Value & ".xlsm"          .SaveAs Filename:=Fichier, FileFormat:=xlOpenXMLWorkbookMacroEnabled          'Tried with, but dosent works .SaveAs Filename:=Fichier, FileFormat:=51          On Error GoTo 0      End With      Set curCell = curCell.Offset(1, 0)  Wend    'supprime la nouvelle feuille  Application.DisplayAlerts = False  newWst.Delete  Application.DisplayAlerts = True    End Sub
Reply With Quote