Feuille PDF
Bonjour, un sujet qui a peut être été traité:
comment puis je extraite une feuille complete de mon fichier excel sous forme pdf sur mac?
Merci
Bonsoir
ci joint un fichier avec un code que j'utilisais pour ouvrir un fichier et faire l'exprt PDF d'une feuille.. a adapter donc...
sous mac c'est tout de suite plus compliqué....
dans le principe
1) on copy la feuille voulus dans un nouveau fichier temporaire,
2) on fait l'export pdf
3) on supprime le fichier temporaire
je mettais inspiré d'un code qui se trouve ici :
http://www.rondebruin.nl/mac/mac005.htm
A+
Fred
edit : pour l'appel de la macro d'enregistrement j'utilisais :
enregistrement_mac (chemin & monfichiersource), (chemin), (monfichierPDF)
Alors en cherchant je suis tombé sur ca aussi, j'y ai rien compris
mon but est d'affectuer la macro a l'image
j'ai pas de mac sous la main et comme tu ne donne pas bcp d'infos....
a tester !!
fred
c'est top!
peut-on lui attribuer par défaut le nom de la feuille?
comment change t'on le chemin d'enregistrement?
Merci
pour le chemin a modifier :
'Folder where you want to save the PDF file, Documents folder in this example
PDFfolder = MacScript("return (path to documents folder) as string")
pour le nom du fichier :
'Enter the file name that you want to use for the PDF, do not add the extension.
PDFfileName = ActiveSheet.Name & Format(Now, "dd-mmm-yy h-mm-ss")
fred
Folder where you want to save the PDF file, Documents folder in this example
PDFfolder = Users/Guillaume/Desktop/
'Enter the file name that you want to use for the PDF, do not add the extension.
PDFfileName = ActiveSheet.Name
Application.ScreenUpdating = False
ce chemin ne fonctionne pas autrement le nom il prends pas le nom
j'ai trouvé ca deja:
'Folder where you want to save the PDF file, Documents folder in this example
PDFfolder = "MacBook/Users/Guillaume/Desktop/"
'Enter the file name that you want to use for the PDF, do not add the extension.
PDFfileName = ActiveSheet.Name & Format(Now, "dd-mmm-yy h-mm-ss")
Mais j'ai ce message d'erreur
Bonjour
alors toi tu raisonne windows.... et pas du tout mac....
par exemple le separateur de dossier sou windows c'est bien le "/" mais sous mac c'est ":"
donc déjà là ça coince... ensuite je ne suis pas sur du tout que ce chemin existe sous mac :
PDFfolder = "MacBook/Users/Guillaume/Desktop/"
pour preuve ajoute un msgbox après l'instruction initiale de recupération du nom de dossier :
'Folder where you want to save the PDF file, Documents folder in this example
PDFfolder = MacScript("return (path to documents folder) as string")
msgbox (PDFfolder)
et tu verras le chemin d'accès au dossier "mes documents" de MAC, ensuite tu n'auras qu'a adapter le chemin en conséquence
fred
J'ai changé, toujours pareil, oui les "/" au lieu de ":" une erreur de débutant
voila mon code:
Option Explicit
Sub enregistrement_mac()
Dim TempPDFFolder As String
Dim PDFfolder As String
Dim PDFfileName As String
'Path to folder where we save the pdf's temporary. The code will create
'the folder named "PDFTempFolder" in your Documents folder for you
'Note: this will not be used when you create a pdf of one sheet but not remove this line
'creation d'un dossier temporaire mais qui ne servira pas je laisse la fonction tel quelle comment indiquee
TempPDFFolder = MacScript("return (path to documents folder) as string") & "PDFTempFolder:"
'Folder where you want to save the PDF file, Documents folder in this example
PDFfolder = "MacBook:Users:Guillaume:Bureau"
MsgBox (PDFfolder)
'Enter the file name that you want to use for the PDF, do not add the extension.
PDFfileName = ActiveSheet.Name & Format(Now, "dd-mmm-yy h-mm-ss")
Application.ScreenUpdating = False
'You can also use this for the activesheet : ActiveSheet.Copy
'Worksheets("Sheet2").Copy
'copie de la feuille dans un nouveau fichier temporaire
ActiveSheet.Copy
'mise au format paysage de la feuille
ActiveSheet.PageSetup.Orientation = xlLandscape
'Do not change the macro call below, you see that we only have one macro call
'if we create a PDF of one sheet because we not have a problem with the bug that
'create a pdf of each worksheet in the workbook because there is only one sheet.
Call MakePDF(TempPDFFolder, PDFfolder, PDFfileName, True)
'Close temporary file
ActiveWorkbook.Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub
'*********Functions used by the macros to create pdf files and create mails with the the pdf attached, do not change them**********
Function MakePDF(TempPDFLocation As String, YourPDFfolder As String, YourPDFName As String, Finish As Boolean)
'Ron de Bruin, Version 2, 13-March-2012
'Function to create a PDF of the ActiveWorkbook in Excel 2011
'Note: The code will not work correct if not all sheets are the same type
'For example it will not work if there is one chart sheet in the workbook
'If the sheets not all use landscape or portrait it is also not working correct
Dim i As Long
Dim SheetName As String
Dim scriptToRun As String
Dim ScriptToMakeDir As String
If ActiveWorkbook.Sheets.Count > 1 Then
'Script to create the Temporary PDF folder if it not exist
ScriptToMakeDir = "tell application " & Chr(34) & _
"Finder" & Chr(34) & Chr(13)
ScriptToMakeDir = ScriptToMakeDir & _
"do shell script ""mkdir -p "" & quoted form of posix path of " & _
Chr(34) & TempPDFLocation & Chr(34) & Chr(13)
ScriptToMakeDir = ScriptToMakeDir & "end tell"
On Error Resume Next
MacScript (ScriptToMakeDir)
On Error GoTo 0
Else
TempPDFLocation = YourPDFfolder
End If
'look for the first sheet name in the workbook
'We need this name so we can remove it from the file name
For i = 1 To ActiveWorkbook.Sheets.Count
If Sheets(i).Visible = True Then
SheetName = Sheets(i).Name
Exit For
End If
Next i
'Save the workbook as PDF, remove the sheet name from the file name(bug) and
'move the PDF to YourPDFfolder if the workbook have more then one worksheet.
scriptToRun = scriptToRun & "tell application " & Chr(34) & _
"Microsoft Excel" & Chr(34) & Chr(13)
scriptToRun = scriptToRun & "save active workbook in (" & _
Chr(34) & TempPDFLocation & "TempName.pdf" & _
Chr(34) & ") as PDF file format" & Chr(13)
scriptToRun = scriptToRun & "end tell" & Chr(13)
If Finish = True Then
scriptToRun = scriptToRun & "tell application " & Chr(34) & _
"Finder" & Chr(34) & Chr(13)
scriptToRun = scriptToRun & "set name of file " & Chr(34) & _
TempPDFLocation & "TempName " & SheetName & ".pdf" & Chr(34) & _
" to " & Chr(34) & YourPDFName & ".pdf" & Chr(34) & Chr(13)
If ActiveWorkbook.Sheets.Count > 1 Then
scriptToRun = scriptToRun & "move " & Chr(34) & TempPDFLocation _
& YourPDFName & ".pdf" & Chr(34) & " to " & Chr(34) & YourPDFfolder & Chr(34) & Chr(13)
End If
scriptToRun = scriptToRun & "end tell" & Chr(13)
End If
On Error Resume Next
MacScript (scriptToRun)
On Error GoTo 0
End Function
Sub DeleteFilesInPDFTempFolder(TempPDFFolder As String)
'Ron de Bruin, 3-Nov-2011
Dim scriptToRun As String
scriptToRun = scriptToRun & "tell application " & Chr(34) & _
"Finder" & Chr(34) & Chr(13)
scriptToRun = scriptToRun & _
"do shell script ""rm "" & quoted form of posix path of " & _
Chr(34) & TempPDFFolder & """ & " & Chr(34) & "*" & Chr(34) & Chr(13)
scriptToRun = scriptToRun & "end tell"
On Error Resume Next
MacScript (scriptToRun)
On Error GoTo 0
End Sub
Function KillFileOnMac(Filestr As String)
'Ron de Bruin, function to Kill file from Mac, 10-Jan-2012
'The VBA Kill command on a Mac will not work with long file names(28+ characters)
Dim ScriptToKillFile As String
ScriptToKillFile = ScriptToKillFile & "tell application " & Chr(34) & _
"Finder" & Chr(34) & Chr(13)
ScriptToKillFile = ScriptToKillFile & _
"do shell script ""rm "" & quoted form of posix path of " & _
Chr(34) & Filestr & Chr(34) & Chr(13)
ScriptToKillFile = ScriptToKillFile & "end tell"
On Error Resume Next
MacScript (ScriptToKillFile)
On Error GoTo 0
End Function
Function FileExistsOnMac(Filestr As String) As Boolean
'Ron de Bruin, function to test if file exist on a Mac, 20-Feb-2012
'No problem with long file names like the other examples(max of 27/28 characters)
Dim ScriptToCheckFile As String
ScriptToCheckFile = "tell application " & Chr(34) & "Finder" & Chr(34) & Chr(13)
ScriptToCheckFile = ScriptToCheckFile & "exists file " & Chr(34) & Filestr & Chr(34) & Chr(13)
ScriptToCheckFile = ScriptToCheckFile & "end tell" & Chr(13)
FileExistsOnMac = MacScript(ScriptToCheckFile)
End Function
Re
J'aime bien le "voici mon code"...
si tu veux placer le fichier pdf sur le bureau essaye de remplacer :
PDFfolder = MacScript("return (path to documents folder) as string")
msgbox (PDFfolder)
par
PDFfolder = MacScript("return (path to desktop folder) as string")
msgbox (PDFfolder)
et verifie que cela correspond a ce que tu as essayé de marqué en dure dans la macro
MacBook:Users:Guillaume:Bureau
fred
Oui pardon c'est pas mon code lol mais c'est pour mon application
Bon le chemin d'accès est bon apparemment et voila ou j'en arrive:
perso j'arrive pas a lire l'image mise a dispo
fred
c'est format tiff je l'a met en pdf
je ne peux rien pour toi....
Le fichier fournis sur le deuxième post fonctionnait d'après tes info
reprend celui la et change uniquement la ligne que je t'ai indiqué précédemment
PDFfolder = MacScript("return (path to desktop folder) as string")
puis si cela marche change le nom du fichier en supprimant la partie mettant la date dans le nom du fichier
PDFfileName = ActiveSheet.Name ' & Format(Now, "dd-mmm-yy h-mm-ss")
sinon n'ayant pas le mac sous la main je ne peux rien pour toi
fred
Edit : aller.... le fichier du deuxième post modifié avec les infos que je te demande de modifier
J'ai oublié de préciser une petite chose, désolé,
avec le code d'origine,
'Path to folder where we save the pdf's temporary. The code will create
'the folder named "PDFTempFolder" in your Documents folder for you
'Note: this will not be used when you create a pdf of one sheet but not remove this line
'creation d'un dossier temporaire mais qui ne servira pas je laisse la fonction tel quelle comment indiquee
TempPDFFolder = MacScript("return (path to documents folder) as string") & "PDFTempFolder:
'Folder where you want to save the PDF file, Documents folder in this example
PDFfolder = MacScript("return (path to documents folder) as string")
'Enter the file name that you want to use for the PDF, do not add the extension.
PDFfileName = ActiveSheet.Name & Format(Now, "dd-mmm-yy h-mm-ss")
Ca ne s'enregistre pas dans document, mais pluto dans;
Le fichier '/Users/Guillaume/Library/Containers/com.microsoft.Excel/Data/Documents/TempName.pdf' existe déjà à cet emplacement.
Le nom reste toujours TempName
refais un essais avec ce fichier
sinon j'abandonne chez moi cela fonctionnait a l'époque... mais cela remonte a loin et je n'ai pas quoi tester sous la main
fred
et puis tu marque
Ca ne s'enregistre pas dans document, mais pluto dans;
Le fichier '/Users/Guillaume/Library/Containers/com.microsoft.Excel/Data/Documents/TempName.pdf' existe déjà à cet emplacement.
cela me dis que tu ne travail pas sous mac..... c'est pas possible, ou alors il y a un truc qui m'échappe
fred
salut, toujours pareil erreur lors de l'impression, je vois pas le rapport.
Je travaille bien sous mac.