#1
|
|||
|
|||
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 |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Save As PDF Macro/VBA with Predetermined File Name | DefinedDesign | Word VBA | 9 | 10-29-2014 01:48 PM |
Choose file name Save As macro | gbaker | Excel Programming | 28 | 07-22-2014 03:54 PM |
Save As Macro that changes the file name also | rosscortb | Word VBA | 5 | 05-19-2014 08:40 AM |
How do I save a Word file with a macro for distribution? | leemoreau | Word VBA | 3 | 10-04-2013 08:06 AM |
Word Macro: Save file as text with current file name | jabberwocky12 | Word VBA | 2 | 10-22-2010 12:23 PM |