Macro Impression PDF chemin HTTP

Snoop

XLDnaute Occasionnel
Bonjour tout le monde,

J'ai trouvé un petit code qui permet d'imprimer des fichiers pdf via excel.

Le seul hic est que cela fonctionne qu'avec des lecteurs local ou reseau mais pas avec comme chemin http... ?

si je lui met 'http:\\12.1.1.1\test\test.pdf --> aucune réaction de la macro:eek:...

Code:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ 
    (ByVal hwnd As Long, ByVal lpOperation As String, _ 
    ByVal lpFile As String, ByVal lpParameters As String, _ 
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long 


Sub ShellImprime() 
Dim fich 
    fich = "Lecteur\Chemin\Complet\Et\Fichier.doc" 
    ShellExecute 0, "print", fich, "", "", 0 
End Sub

Merci pour votre aide... :D
 
G

Guest

Guest
Re : Macro Impression PDF chemin HTTP

re:

c'est vrai qu'avec une URL internet tu ne peux que ouvrir le fichier concerné par ShellExecute avec 'open' au lieu de 'print'. Cela ouvrira le fichier dans le navigateur internet par défaut.

Code:
Sub ShellImprime()
Dim fich
    fich = ""
    ShellExecute 0, "[COLOR=red]open[/COLOR]", fich, "", "", 0
End Sub

Je vais voir si je ne trouve pas un autre truc.
en attendant patiente... Peut-être qu'un surdoué passera par là.

A bientôt
 
Dernière modification par un modérateur:

Staple1600

XLDnaute Barbatruc
Re : Macro Impression PDF chemin HTTP

Bonjour à tous



A tester et adapter
Code:
Sub Tester()
Dim Ret As Long, myAddress1 As String, myAddress2 As String, myPath As String
myAddress1 = ActiveCell.Address
myAddress2 = "$B$" & Right(myAddress1, 1)
myPath = Range(myAddress1).Value + Range(myAddress2).Value
'// Substitute here your Doc full path
Ret = fnShellOperation([B]myPath[/B], "[B]print"[/B], SW_MAXIMIZE)
End Sub
'---------------------------------------------------------------------------------------

' Module : basShellOp

' DateTime : 29/09/03 18:31

' Author : Ivan F Moala

' Purpose : Opens ANY Document/File

'---------------------------------------------------------------------------------------
Option Explicit
Public Declare Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long

Public Declare Function GetDesktopWindow _
Lib "user32" () _
As Long

Private Const SW_HIDE As Long = 0
Private Const SW_NORMAL As Long = 1
Private Const SW_MAXIMIZE As Long = 3
Private Const SW_MINIMIZE As Long = 6
'//---------------------------------------------------------------------------------------

'// Function : fnShellOperation

'// DateTime : 20/09/03 20:50

'// Author : "Ivan F Moala"
'// Site : "http://www.xcelfiles.com" 

'// Purpose : Performs an operation eg Open,Print

'// : a specified file. The file can be an executable file or a document file.

'---------------------------------------------------------------------------------------
Public Function fnShellOperation(strFilePath As String, _
Optional strOperation As String, _
Optional nShowCmd As Double) As Long
Dim hWndDesk As Long

'// use the desktop as default ... you should use your App.handle

hWndDesk = GetDesktopWindow()
If Len(strOperation) = 0 Then strOperation = "Open"
If nShowCmd = Null Then nShowCmd = SW_MAXIMIZE
'// Failure when >0 or <=32
fnShellOperation = ShellExecute(hWndDesk, strOperation, strFilePath, 0, 0, nShowCmd)

If fnShellOperation <= 32 Then
MsgBox "Couldn't " & strOperation & " " & strFilePath & vbCrLf & vbCrLf & _
"Error:= " & fnShellErr(fnShellOperation)
End If
'// OK check IF there was an Association Error
If fnShellOperation = 31 Then

'// OK Ask user if they want to Open it using another program

If MsgBox(strOperation & " Using another Application", vbYesNo) = vbYes Then

Shell "rundll32.exe shell32.dll,OpenAs_RunDLL " & strFilePath, vbNormalFocus

End If

End If

End Function

 

'//---------------------------------------------------------------------------------------

'// Function : fnShellErr

'// DateTime : 20/09/03 20:50

'// Author : "Ivan F Moala"
'// Site : "http://www.xcelfiles.com" 

'// Purpose :

'---------------------------------------------------------------------------------------

Public Function fnShellErr(Ret As Long) As String
Select Case Ret

'// Typical Errors

Case 0: fnShellErr = "The operating system is out of memory or resources."

Case Is = 2: fnShellErr = "The specified FILE was not found."

Case Is = 3: fnShellErr = "The specified PATH was not found."

Case Is = 5: fnShellErr = "The operating system denied access to the specified file."

Case Is = 8: fnShellErr = "There was not enough memory to complete the operation."

Case Is = 11: fnShellErr = "The .EXE file is invalid (non-Win32 .EXE or error in .EXE image)."
Case Is = 26: fnShellErr = "A sharing violation occurred."
Case Is = 27: fnShellErr = "The filename association is incomplete or invalid."
Case Is = 28: fnShellErr = "The DDE transaction could not be completed because the request timed out."
Case Is = 29: fnShellErr = "The DDE transaction failed."
Case Is = 30: fnShellErr = "The DDE transaction could not be completed because other DDE transactions were being processed."
Case Is = 31: fnShellErr = "There is no application associated with the given filename extension."
Case Is = 32: fnShellErr = "The specified dynamic-link library was not found."
Case Else: fnShellErr = "*UNDEFINED* Error"
End Select
End Function

source de la macro d'origine
 
Dernière édition:

Staple1600

XLDnaute Barbatruc
Re : Macro Impression PDF chemin HTTP

Re



Nettement plus simple (et court) ici:
(Je te laisse tester car pas d'imprimante sur le PC d'ou je poste)
Code:
Sub Print_PDF_Test1()
'Need a reference to Microsoft Internet Controls
'for just testing:PDF files will be placed in the local server.
    Const cnsPDF_FILE As String = _
            "http://www.framasoft.net/IMG/pdf/diapo_impress.pdf"
    Dim ObjIE As New InternetExplorer
    ObjIE.Navigate cnsPDF_FILE
    ObjIE.Visible = True
    Do While ObjIE.Busy = True: DoEvents: Loop
    'The following line shows a setup dialog of Acrobat
    ObjIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT
End Sub

source
 

Snoop

XLDnaute Occasionnel
Re : Macro Impression PDF chemin HTTP

Bonjour Staple,

Je viens de tester le deux macro :

La 1er : impression impossible message d'erreur du fait du print.

La 2em : la ligne "ObjIE As New InternetExplorer" est en erreur -> erreur de compilation. il doit manquer une reference sur l'objet ?

Merci
 

Staple1600

XLDnaute Barbatruc
Re : Macro Impression PDF chemin HTTP

Re



Tu as activé : Microsoft Internet Controls?

Essaye aussi en activant
Microsoft HTML Object Library
(Dans VBE ->Outils/Références)


Et reteste la dernière macro (la plus courte)

EDITION:
Et en mixant ce code (issu des pages MichelXLD de la FAQ) ?
Code:
Sub imprimerPageWeb() 
Dim IE As internetExplorer 
Set IE = createObject("internetExplorer.Application") 
IE.Visible = True 
IE.navigate "http://www.mappy.fr" 
Do Until IE.readyState = READYSTATE_COMPLETE 
doEvents 
Loop 
IE.ExecWB [B]OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER [/B]
End Sub

Essayes de mettre les mots en gras dans la précédente macro
ou change l'url dans celle-ci.

Bons tests.

PS: 'necessite d'activer la reference Microsoft Internet Controls
(comme dit dans la FAQ)
 
Dernière édition:

Snoop

XLDnaute Occasionnel
Re : Macro Impression PDF chemin HTTP

Re,

ok, cela fonctionne, 1er etape de passer...

Maintenant, je doit faire de l'impression de masse, et donc ouvrir x page pour impression...*

Donc qu'il m'imprime le tout sans me demander l'imprimante et qu'il n'ouvre pas ou en cacher la fenetre;;;;:D:D:D:D:D

Merci en tout cas pour le code, celui-ci va m'aider bcp
 

Snoop

XLDnaute Occasionnel
Re : Macro Impression PDF chemin HTTP

J'ai juste rajouté a ton code une boucle pour lui faire imprimer des liens html qui sont sur excel.

Sub Print_PDF_Test2()
'Need a reference to Microsoft Internet Controls
'for just testing:pDF files will be placed in the local server.
Dim ObjIE As New InternetExplorer
'Set ObjIE = CreateObject("InternetExplorer.Application")
Dim cnsPDF_FILE As String
Dim i As Integer

i = 1
While Range("a" & i) <> ""

cnsPDF_FILE = Range("a" & i).Value

ObjIE.Navigate cnsPDF_FILE
ObjIE.Visible = True
Do While ObjIE.Busy = True: DoEvents: Loop
'The following line shows a setup dialog of Acrobat
'ObjIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT

ObjIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER

i = i + 1
Wend

End Sub

Il reste une erreur, il m'imprime que la Derniere ligne meme si il me demande l'impression pour les autres images :eek:)

La seule chose, est queje voudrais qu'il ne me demande pas l'impression, mais qu'il le fasse en automatique.
 
Dernière édition:

Discussions similaires

Réponses
4
Affichages
468
Réponses
1
Affichages
1 K
Compte Supprimé 979
C
Réponses
7
Affichages
1 K

Statistiques des forums

Discussions
312 429
Messages
2 088 349
Membres
103 822
dernier inscrit
kader55