Bonjour
Vous allez avoir besoin de cette fonction pour exporter
Sub ExportPDF(oPath As String, oFileName As String, oDocument As Document, oOptions As NameValueMap)
' Get the PDF translator Add-In.
Dim PDFAddIn As TranslatorAddIn
Set PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
' Create a DataMedium object
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
'Set the destination file name
oDataMedium.filename = oPath & oFileName
'Publish document.
Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub
Et derrière il faut préparer l'export avec diverses fonction (mais à adapter)
Fonction dépendant d'un bouton sur un formulaire VB
Private Sub btnExportPdf_Click()
' Create a NameValueMap object
Dim oOptions As NameValueMap, oDirectory As String, oFileName As String, oFileDialog As Inventor.FileDialog
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oOptions.value("All_Color_AS_Black") = cbBW.value
oOptions.value("Remove_Line_Weights") = cbLineWeights.value
Dim Vector As Integer
Vector = TBResolution.value
oOptions.value("Vector_Resolution") = Vector
If OptBtnAllSheets.value Then
oOptions.value("Sheet_Range") = kPrintAllSheets
End If
If OptBtnCurrentSheet Then
oOptions.value("Sheet_Range") = kPrintCurrentSheet
End If
If OptBtnSheets Then
Dim sFrom As Integer
Dim sTo As Integer
sFrom = TBSheetFrom.value
sTo = TBSheetTo.value
oOptions.value("Sheet_Range") = kPrintSheetRange
oOptions.value("Custom_Begin_Sheet") = sFrom
oOptions.value("Custom_End_Sheet") = sTo
End If
If OptBtnDirectoryChoice Then
Set oFileDialog = Nothing
Call ThisApplication.CreateFileDialog(oFileDialog)
oFileDialog.Filter = "Adobe Acrobe PDF files (*.pdf)|*.pdf"
oFileDialog.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
oFileDialog.CancelError = True
If OptBtnCustomFileName Then
oFileDialog.filename = TBCustomFileName.text
Else
oFileDialog.filename = getFileName(ThisApplication.ActiveDocument.FullFileName) & ".pdf"
End If
On Error Resume Next
Call oFileDialog.ShowSave
If err.Number <> 0 Then
Exit Sub
ElseIf oFileDialog.filename = "" Then
MsgBox "Le nom du fichier est vide"
Exit Sub
Else
oFileName = oFileDialog.filename
End If
Else
oDirectory = getPath(ThisApplication.ActiveDocument.FullFileName)
If OptBtnCustomFileName Then
oFileName = TBCustomFileName.text & ".pdf"
Else
oFileName = getFileName(ThisApplication.ActiveDocument.FullFileName) & ".pdf"
End If
End If
Call ExportPDF(oDirectory, oFileName, ThisApplication.ActiveDocument, oOptions)
End Sub
Vous aurez uniquement besoin " oOptions.value("Sheet_Range") = kPrintCurrentSheet" et il faut penser à activer la feuille avant de faire l'export (mais je suppose que c'est déjà le cas pour vos exports ?)
En gros il faut parcourir les feuilles, comparer le nom de la feuille avec vos conditions, l'activer et faire l'export pdf.
Fonction pour le getPath
Function getPath(oDocFullPath As String) As String
getPath = Left(oDocFullPath, InStrRev(oDocFullPath, "\"))
End Function
Fonction pour le getFileName
Function getFileName(oDocFullPath As String) As String
Dim oDocNameWOExtension As String
oDocNameWOExtension = Right(oDocFullPath, Len(oDocFullPath) - InStrRev(oDocFullPath, "\"))
getFileName = Left(oDocNameWOExtension, InStrRev(oDocNameWOExtension, ".") - 1)
End Function
Ces deux fonctions peuvent être mises dans un module à part