Hello
Is it possible to have the address of the export directory as a hyperlink in a Userform of a VBA macro.
I want to use my PDF DXF STEP ZIP export macro, ... and that at the end of the operation, in addition to having the message "operation completed successfully", I want to have either a hypertext link to this directory, or a button to access it.
The ultimate would even be to have a "Send by email" button that would open a new message with a predefined subject and content and attach the exported document to it. It's for my requests that come up quite often. Thank you for your help.
This may give you a clue by replacing internet explorer with windows explorer:
https://forum.solidworks.com/thread/207477
I did it.
I ended up doing a UserForm and the macro replaces a Text field with the file name or directory address. I used the userform 's _Click settings to Open in hyperlink style (I made a change in mouse formatting by the "main" style) when hovering over the text field, and I put a button to access the directory:
Private Sub LabelFileExport_Click()
On Error GoTo OuvertureFichierErreur
Dim MonApplication As Object
Dim MonFichier As String
Set MonApplication = CreateObject("Shell.Application")
MonFichier = vDestinationPath & "\" & sRefName & ".zip"
MonApplication.Open (MonFichier)
Set MonApplication = Nothing
Exit Sub
OuvertureFichierErreur:
Set MonApplication = Nothing
MsgBox "Erreur lors de l'ouverture de fichier..."
End Sub
Private Sub CommandButtonOpenPath_Click()
Shell Environ("WINDIR") & "\explorer.exe " & vDestinationPath, vbNormalFocus
End Sub
For sending an email with the attachment, I found a response in pieces on several forums and it looks like this:
Private Sub CommandButtonSendMail_Click()
On Error GoTo EnvoyerEmailErreur
'définition des variables
Dim oOutlook As Outlook.Application
Dim oMailItem As Outlook.MailItem
Dim Body As Variant
Dim sTmp As String, SigString As String
Dim Signature As String
Dim strbody As String
PieceJointe = vDestinationPath & "\" & sRefName & ".zip"
'préparer Outlook
PreparerOutlook oOutlook
Set oMailItem = oOutlook.CreateItem(0)
strbody = "<font size=3>" _
& "Bonjour,<br>" _
& "Pouvez-vous s'il vous plaît me faire votre meilleure offre de prix et délais pour la fourniture de l'élément en plan ci-joint.<br>" _
& "Cordialement,"
'création de l'email
With oMailItem
.Display '<- affiche l'email (si vous ne voulez pas l'afficher, mettez cette ligne en commentaire)
.Subject = "Demande de prix - " & sRefName
.HTMLBody = strbody & .HTMLBody
If PieceJointe <> "" Then .Attachments.Add PieceJointe
'.Save '<- sauvegarde l'email avant l'envoi (pour ne pas le sauvegarder, mettez cette ligne en commentaire)
'.Send '<- envoie l'email (si vous voulez seulement préparer l'email et l'envoyer manuellement, mettez cette ligne en commentaire)
End With
'nettoyage...
If (Not (oMailItem Is Nothing)) Then Set oMailItem = Nothing
If (Not (oOutlook Is Nothing)) Then Set oOutlook = Nothing
Exit Sub
EnvoyerEmailErreur:
If (Not (oMailItem Is Nothing)) Then Set oMailItem = Nothing
If (Not (oOutlook Is Nothing)) Then Set oOutlook = Nothing
MsgBox "Le mail n'a pas pu être envoyé...", vbCritical, "Erreur"
End Sub
Private Sub PreparerOutlook(ByRef oOutlook As Object)
'Ce code vérifie si Outlook est prêt à envoyer des emails... Et s'il ne l'est pas, il le prépare.
On Error Resume Next
'vérification si Outlook est ouvert
Set oOutlook = GetObject(, "Outlook.Application")
If (Err.Number <> 0) Then 'si Outlook n'est pas ouvert, une instance est ouverte
Err.Clear
Set oOutlook = CreateObject("Outlook.Application")
If (Err.Number <> 0) Then
MsgBox "Une erreur est survenue lors de l'ouverture de Outlook..."
Exit Sub
Else
End If
Else 'si Outlook est ouvert, l'instance existante est utilisée
End If
End Sub