1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
| '*******************************
'* Build on original gsapi_vb6 *
'*******************************
'Release version : CutePdf Write Advanced Setup for office V2008_V2.2B Beta 2008-06-26 14:34:43
'Attribute VB_Name = "gsapi_vb6"
' Copyright (c) 2002 Dan Mount and Ghostgum Software Pty Ltd
'
' Permission is hereby granted, free of charge, to any person obtaining
' a copy of this software and associated documentation files (the
' "Software"), to deal in the Software without restriction, including
' without limitation the rights to use, copy, modify, merge, publish,
' distribute, sublicense, and/or sell copies of the Software, and to
' permit persons to whom the Software is furnished to do so, subject to
' the following conditions:
'
' The above copyright notice and this permission notice shall be
' included in all copies or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
' EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
' MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
' BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
' ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
' CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
' SOFTWARE.
' This is an example of how to call the Ghostscript DLL from
' Visual Basic for Application. This example converts .ps to .PDF
' The display device is not supported.
'
Option Explicit
'Flags ShellExecuteEx
Private Const SEE_MASK_NOCLOSEPROCESS = &H40
Private Const SEE_MASK_FLAG_NO_UI = &H400
'Constantes ERREUR ShellExecuteEx
Private Const SE_ERR_FNF As Byte = 2
Private Const SE_ERR_PNF As Byte = 3
Private Const SE_ERR_ACCESSDENIED As Byte = 5
Private Const SE_ERR_OOM As Byte = 8
Private Const SE_ERR_SHARE As Byte = 26
Private Const SE_ERR_ASSOCINCOMPLETE As Byte = 27
Private Const SE_ERR_DDETIMEOUT As Byte = 28
Private Const SE_ERR_DDEFAIL As Byte = 29
Private Const SE_ERR_DDEBUSY As Byte = 30
Private Const SE_ERR_NOASSOC As Byte = 31
Private Const SE_ERR_DLLNOTFOUND As Byte = 32
'Constantes AFFICHAGE ShellExecuteEx
Private Const SW_SHOWNORMAL = 1
Private Const SW_SHOW = 5
Private Const SW_SHOWDEFAULT = 10
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hWnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
'OpenProgram
Private Declare Function ShellExecuteEx Lib "shell32.dll" _
(SEI As SHELLEXECUTEINFO) As Long
'CloseProgram
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Public Const WM_CLOSE = &H10
Const GW_HWNDNEXT = 2
Dim Gsapi_mWnd As Long
Dim Gsapi_PhWnd As Long
Dim Gsapi_P_Attachement_file As String
Private AppCible As String
Public Const Duree_Gsapi_Convert = 10 'secondes
Public Gsapi_Vba_pdf_name As String
Const ERROR_NO_MORE_ITEMS = 259&
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_LOCAL_MACHINE = &H80000002
'------------------------------------------------
'API Calls Start
'------------------------------------------------
'Win32 API
'GhostScript API
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal dest As Long, ByVal source As Long, ByVal bytes As Long)
Private Declare Function gsapi_revision Lib "gsdll32.dll" (ByVal pGSRevisionInfo As Long, ByVal intLen As Long) As Long
Private Declare Function gsapi_new_instance Lib "gsdll32.dll" (ByRef lngGSInstance As Long, ByVal lngCallerHandle As Long) As Long
Private Declare Function gsapi_set_stdio Lib "gsdll32.dll" (ByVal lngGSInstance As Long, ByVal gsdll_stdin As Long, ByVal gsdll_stdout As Long, ByVal gsdll_stderr As Long) As Long
Private Declare Sub gsapi_delete_instance Lib "gsdll32.dll" (ByVal lngGSInstance As Long)
Private Declare Function gsapi_init_with_args Lib "gsdll32.dll" (ByVal lngGSInstance As Long, ByVal lngArgumentCount As Long, ByVal lngArguments As Long) As Long
Private Declare Function gsapi_run_file Lib "gsdll32.dll" (ByVal lngGSInstance As Long, ByVal strFileName As String, ByVal intErrors As Long, ByVal intExitCode As Long) As Long
Private Declare Function gsapi_exit Lib "gsdll32.dll" (ByVal lngGSInstance As Long) As Long
'------------------------------------------------
' >>>> Godz Add
'------------------------------------------------
Private Declare Function SHCreateDirectoryEx Lib "shell32.dll" Alias "SHCreateDirectoryExA" _
(ByVal hWnd As Long, ByVal pszPath As String, ByVal lngsec As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
'------------------------------------------------
' <<<< Godz Add
'------------------------------------------------
'------------------------------------------------
'API Calls End
'------------------------------------------------
'------------------------------------------------
'UDTs Start
'------------------------------------------------
Private Type GS_Revision
strProduct As Long
strCopyright As Long
intRevision As Long
intRevisionDate As Long
End Type
'------------------------------------------------
'UDTs End
'------------------------------------------------
'------------------------------------------------
'Callback Functions Start
'------------------------------------------------
'These are only required if you use gsapi_set_stdio
Public Function gsdll_stdin(ByVal intGSInstanceHandle As Long, ByVal strz As Long, ByVal intBytes As Long) As Long
' We don't have a console, so just return EOF
gsdll_stdin = 0
End Function
Public Function gsdll_stdout(ByVal intGSInstanceHandle As Long, ByVal strz As Long, ByVal intBytes As Long) As Long
' If you can think of a more efficient method, please tell me!
' We need to convert from a byte buffer to a string
' First we create a byte array of the appropriate size
Dim aByte() As Byte
ReDim aByte(intBytes)
' Then we get the address of the byte array
Dim ptrByte As Long
ptrByte = VarPtr(aByte(0))
' Then we copy the buffer to the byte array
CopyMemory ptrByte, strz, intBytes
' Then we copy the byte array to a string, character by character
Dim str As String
Dim i As Long
For i = 0 To intBytes - 1
str = str + Chr(aByte(i))
Next
' Finally we output the message
'>>GODZ>>>>Debug.Print (str)
'>>GODZ>>>>MsgBox (str)
gsdll_stdout = intBytes
End Function
Public Function gsdll_stderr(ByVal intGSInstanceHandle As Long, ByVal strz As Long, ByVal intBytes As Long) As Long
gsdll_stderr = gsdll_stdout(intGSInstanceHandle, strz, intBytes)
End Function
'------------------------------------------------
'Callback Functions End
'------------------------------------------------
'------------------------------------------------
'User Defined Functions Start
'------------------------------------------------
Public Function AnsiZtoString(ByVal strz As Long) As String
Rem We need to convert from a byte buffer to a string
Dim byteCh(1) As Byte
Dim bOK As Boolean
bOK = True
Dim ptrByte As Long
ptrByte = VarPtr(byteCh(0))
Dim j As Long
j = 0
Dim str As String
While bOK
' This is how to do pointer arithmetic!
CopyMemory ptrByte, strz + j, 1
If byteCh(0) = 0 Then
bOK = False
Else
str = str + Chr(byteCh(0))
End If
j = j + 1
Wend
AnsiZtoString = str
End Function
Public Function CheckRevision(ByVal intRevision As Long) As Boolean
' Check revision number of Ghostscript
Dim intReturn As Long
Dim udtGSRevInfo As GS_Revision
intReturn = gsapi_revision(VarPtr(udtGSRevInfo), 16)
Dim str As String
str = "Revision=" & udtGSRevInfo.intRevision
str = str & " RevisionDate=" & udtGSRevInfo.intRevisionDate
str = str & " Product=" & AnsiZtoString(udtGSRevInfo.strProduct)
str = str & " Copyright = " & AnsiZtoString(udtGSRevInfo.strCopyright)
'>>GODZ>>>>Debug.Print (str)
'>>GODZ>>>>MsgBox (str)
If udtGSRevInfo.intRevision = intRevision Then
CheckRevision = True
Else
CheckRevision = False
End If
End Function
Public Function CallGS(ByRef astrGSArgs() As String) As Boolean
Dim intReturn As Long
Dim intGSInstanceHandle As Long
Dim aAnsiArgs() As String
Dim aPtrArgs() As Long
Dim intCounter As Long
Dim intElementCount As Long
Dim iTemp As Long
Dim callerHandle As Long
Dim ptrArgs As Long
' Print out the revision details.
' If we want to insist on a particular version of Ghostscript
' we should check the return value of CheckRevision().
CheckRevision (704)
' Load Ghostscript and get the instance handle
intReturn = gsapi_new_instance(intGSInstanceHandle, callerHandle)
If (intReturn < 0) Then
CallGS = False
Return
End If
' Capture stdio
intReturn = gsapi_set_stdio(intGSInstanceHandle, AddressOf gsdll_stdin, AddressOf gsdll_stdout, AddressOf gsdll_stderr)
If (intReturn >= 0) Then
' Convert the Unicode strings to null terminated ANSI byte arrays
' then get pointers to the byte arrays.
intElementCount = UBound(astrGSArgs)
ReDim aAnsiArgs(intElementCount)
ReDim aPtrArgs(intElementCount)
For intCounter = 0 To intElementCount
aAnsiArgs(intCounter) = StrConv(astrGSArgs(intCounter), vbFromUnicode)
aPtrArgs(intCounter) = StrPtr(aAnsiArgs(intCounter))
Next
ptrArgs = VarPtr(aPtrArgs(0))
intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount + 1, ptrArgs)
' Stop the Ghostscript interpreter
gsapi_exit (intGSInstanceHandle)
End If
' release the Ghostscript instance handle
gsapi_delete_instance (intGSInstanceHandle)
If (intReturn >= 0) Then
CallGS = True
Else
CallGS = False
End If
End Function
Private Function ConvertFile(Ps_file As Variant, Pdf_file As Variant) As Boolean
Dim astrArgs(10) As String
astrArgs(0) = "ps2pdf" 'The First Parameter is Ignored
astrArgs(1) = "-dNOPAUSE"
astrArgs(2) = "-dBATCH"
astrArgs(3) = "-dSAFER"
astrArgs(4) = "-r300"
astrArgs(5) = "-sDEVICE=pdfwrite"
astrArgs(6) = "-sOutputFile=" & Trim(Pdf_file)
'astrArgs(6) = "-sOutputFile=c:\out.pdf"
astrArgs(7) = "-c"
astrArgs(8) = ".setpdfwrite"
astrArgs(9) = "-f"
astrArgs(10) = Trim(Ps_file)
'astrArgs(10) = "c:\data\test.ps"
ConvertFile = CallGS(astrArgs)
End Function
'------------------------------------------------
'User Defined Functions End
'------------------------------------------------
'Sub Main()
' MsgBox ("Done")
'End Sub
'-------------------------------------------------------------------------
'CONVERTOPDF_Silent : Run ConvertToPDf in Quiet mode
'-------------------------------------------------------------------------
Sub Converttopdf_silent()
Dim silence As Boolean
Dim Gs As Boolean
Dim CutePdf As Boolean
Gs = Check_Ghostscript_dll()
If Not Gs Then
Exit Sub
End If
CutePdf = Check_CutePdf_Writer()
If Not CutePdf Then
Exit Sub
End If
silence = True
Converttopdf silence
End Sub
'-------------------------------------------------------------------------
'CONVERTOPDF_Interactive : Run ConvertToPDf in Interactive
'-------------------------------------------------------------------------
Sub Converttopdf_Interactive()
Dim silence As Boolean
Dim Gs As Boolean
Dim CutePdf As Boolean
Gs = Check_Ghostscript_dll()
If Not Gs Then
MsgBox "Missing gsdll32.dll in SystemRoot. Please Run Setup"
Exit Sub
End If
CutePdf = Check_CutePdf_Writer()
If Not Gs Then
MsgBox "Missing CutePdf Writer. Please Run Setup"
Exit Sub
End If
silence = False
Converttopdf silence
End Sub
'-------------------------------------------------------------------------
'CONVERTOPDF : Convert Print Area to PDF using Original File Path and name
'-------------------------------------------------------------------------
'GODZESTLA : 06/06/2008
'-------------------------------------------------------------------------
'Technical requirements
'-------------------------------------------------------------------------
'1.) CutePDF Writer (Free) Installed : See http://www.cutepdf.com/download/CuteWriter.exe
'
' .A) CuteWriter to be installed with Standard Options.
' .B) Do not install Additional Ghostscript Converter (8.15) when pop-up windows ask for that.
'2.) Ghostscript 8.61 or higher (Free) installed
' .A) See http://downloads.sourceforge.net/ghostscript/gs861w32.exe?modtime=1196280996&big_mirror=1
'3) File gsdll32.dll from C:\Program Files\gs\gsx.yy\bin is copied at Windows\system32
'-------------------------------------------------------------------------
' Parms : Quiet_mode = True : No message at all
'-------------------------------------------------------------------------
Sub Converttopdf(quiet_mode As Boolean)
Dim ps_path As String 'Temporary PostScript Path
Dim ps_fullname As String 'Temporary PoStcript Full Name
Dim AppFullName As String 'Application FullNAme
Dim PdFFullName As String 'PDF FullName
Dim ret As Variant
Dim Current_printer As String 'Current Active printer
Dim Active_printer As String
AppFullName = ActiveDocument.Fullname
If ActiveDocument.Name = ActiveDocument.Fullname Then
If Not quiet_mode Then
MsgBox ActiveDocument.Fullname & ": Veuillez d'abord sauver le document WORD", vbCritical
End If
GoTo abort
End If
'*-------------------------------------------------------------------------
'* Check Postscript temporary folder exists or create
'*-------------------------------------------------------------------------
ps_path = "C:\temp"
SHCreateDirectoryEx 0&, ps_path, 0&
'*-------------------------------------------------------------------------
'* Full temporary postscript file is C:\temp\temp.ps
'*-------------------------------------------------------------------------
ps_fullname = Trim(ps_path) & "\temp.ps"
'*-------------------------------------------------------------------------
'* Scratch Full temporary postscript file if exists
'*-------------------------------------------------------------------------
On Error Resume Next
Kill ps_fullname
'*-------------------------------------------------------------------------
'* Print Selection Using CutePDF Writer producing temporary postscript file
'*-------------------------------------------------------------------------
Current_printer = Application.ActivePrinter
Application.ActivePrinter = "CutePDF Writer"
Application.PrintOut Copies:=1, Filename:=ActiveDocument.Fullname, _
PrintTofile:=True, Collate:=True, OutputFileName:=ps_fullname, _
Pagetype:=wdPrintAllPages, Background:=False
Application.ActivePrinter = Current_printer
'*-------------------------------------------------------------------------
'* Set-up Full PDF Filename = Excel workbookname replacing xls by pdf
'*-------------------------------------------------------------------------
PdFFullName = Left(AppFullName, Len(Trim(AppFullName)) - 3) & "PDF"
'*-------------------------------------------------------------------------
'* Converts Temp Postscript File to PDF
'*-------------------------------------------------------------------------
If Not quiet_mode Then
Call Demarrer_UserForm_PSTOPDF
UserForm1.Show
End If
Call ConvertFile(ps_fullname, PdFFullName)
DoEvents
Kill ps_fullname
If Not quiet_mode Then
Unload UserForm1
'Show Attachement With Default Viewer
Gsapi_PhWnd = OpenProgram(PdFFullName, 0)
'MsgBox PdFFullName & " sucessfully generated", vbInformation
'ret = Shell("Explorer " & PdFFullName, vbNormalFocus)
End If
abort:
End Sub
Function Check_Ghostscript_dll() As Boolean
Dim system32path As String
Dim Gs_fullname As String
Dim res As Variant
Gs_fullname = Environ$("systemroot") & "\System32\" & "gsdll32.dll"
res = Dir(Gs_fullname, vbSystem)
If res = "" Then
Check_Ghostscript_dll = False
Else
Check_Ghostscript_dll = True
End If
End Function
Function Check_CutePdf_Writer() As Boolean
Dim objWMIService As Object, colInstalledPrinters As Object, objPrinter As Object
Dim nomPC As String, Resultat As String
nomPC = "."
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & nomPC & "\root\cimv2")
Set colInstalledPrinters = objWMIService.execQuery("Select * from Win32_Printer")
For Each objPrinter In colInstalledPrinters
If Trim(objPrinter.Name = "CutePDF Writer") Then
Check_CutePdf_Writer = True
Exit Function
End If
Next
Check_CutePdf_Writer = False
End Function
Function Retrieve_Ghoscript_Package() As Variant
Dim hKey As Long, Cnt As Long, sName As String, sData As String, ret As Long, RetData As Long
Const BUFFER_SIZE As Long = 255
Const ERROR_NO_MORE_ITEMS = 259&
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_LOCAL_MACHINE = &H80000002
Dim Release As String
Dim Ghoscript_Key As String
Dim objWSH As Object
ret = BUFFER_SIZE
' "RegEnumKeyEx"
'Open the registry key
If RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\GPL Ghostscript", hKey) = 0 Then
'Create a buffer
sName = Space(BUFFER_SIZE)
'Enumerate the keys
While RegEnumKeyEx(hKey, Cnt, sName, ret, ByVal 0&, vbNullString, ByVal 0&, ByVal 0&) <> ERROR_NO_MORE_ITEMS
'Show the enumerated key
Debug.Print " " + Left$(sName, ret)
Ghoscript_Key = "HKEY_LOCAL_MACHINE\SOFTWARE\GPL Ghostscript\" & Left$(sName, ret) & "\" & "GS_DLL"
'prepare for the next key
Cnt = Cnt + 1
sName = Space(BUFFER_SIZE)
ret = BUFFER_SIZE
Wend
'close the registry key
RegCloseKey hKey
Else
Debug.Print " Error while calling RegOpenKey"
End If
'Read Ghoscript Key
Set objWSH = CreateObject("WScript.Shell")
On Error Resume Next
MsgBox objWSH.RegRead(Ghoscript_Key)
If Err.Number <> 0 Then _
MsgBox "La clé """ & Ghoscript_Key & """ n'existe pas dans la base de registre."
On Error GoTo 0
Set objWSH = Nothing
End Function
Sub AutoExec()
Scrap_toolbars_Cutepdf
AjouterCutePdfCommandBar_Word
End Sub
Sub Autoexit()
Scrap_toolbars_Cutepdf
End Sub
Sub Scrap_toolbars_Cutepdf()
Dim tb As CommandBar
For Each tb In Application.CommandBars
If tb.BuiltIn = False Then
'If tb.Name = "MyCutePDF" Then
tb.Visible = False
tb.Delete
'End If
End If
Next
End Sub
Sub check_toolbars_Cutepdf()
Dim tb As CommandBar
For Each tb In Application.CommandBars
If tb.BuiltIn = False Then
If tb.Name = "MyCutePDF" Then
Debug.Print tb.Name & " " & tb.Context
End If
End If
Next
End Sub
Sub SupprimerCutePdfCommandBar_word()
Dim NomDeLaBarre
NomDeLaBarre = "MyCutePDF"
'Si la barre existe déjà, valider la ligne suivante
On Error Resume Next
Application.CommandBars(NomDeLaBarre).Delete
'On Error GoTo 0
End Sub
Sub AjouterCutePdfCommandBar_Word()
Dim NomDeLaBarre
NomDeLaBarre = "MyCutePDF"
'Si la barre existe déjà, valider la ligne suivante
On Error Resume Next
Application.CommandBars(NomDeLaBarre).Delete
On Error GoTo 0
'Pour créer une barre de commande
'1 => affiche la barre en haut, true => barre provisoire
Application.CommandBars.Add("MyCutePDF", msoBarTop, MenuBar:=False, Temporary:=True).Protection = msoBarNoProtection
Application.CommandBars("MyCutePDF").Visible = True
Bouton_Word_Convertopdf_Interactive
Bouton_Word_Convertopdf_Silent
End Sub
Sub Bouton_Word_Convertopdf_Interactive()
Dim LaBarre As CommandBar
Dim LeBouton As CommandBarButton
Dim picImage As IPictureDisp
Dim NomDeLaBarre, NomMacro, NomClasseur, CheminEtNomImage, ActionDubouton As String
ActionDubouton = "Print in PDF using CutePDF (Interactive Mode)"
NomDeLaBarre = "MyCutePDF"
NomMacro = "Converttopdf_Interactive"
NomClasseur = "Module1" 'GhostScript Api's
CheminEtNomImage = Application.Path & "\BITMAPS\CutePDf\Icon_Pdf_1.bmp"
'Charge l'icone du bouton
Set picImage = LoadPicture(CheminEtNomImage)
Set LaBarre = Application.CommandBars(NomDeLaBarre)
'Ajoute le bouton à la barre d'outils personnalisée
Set LeBouton = LaBarre.Controls.Add(Type:=msoControlButton)
LeBouton.FaceId = 0
LeBouton.Caption = ActionDubouton 'info-bulle du bouton
LeBouton.OnAction = NomClasseur & "." & NomMacro
'Collage de l'image sur le bouton
LeBouton.Picture = picImage
Set LaBarre = Nothing
Set LeBouton = Nothing
End Sub
Sub Bouton_Word_Convertopdf_Silent()
Dim LaBarre As CommandBar
Dim LeBouton As CommandBarButton
Dim picImage As IPictureDisp
Dim NomDeLaBarre, NomMacro, NomClasseur, CheminEtNomImage, ActionDubouton As String
ActionDubouton = "Print in PDF using CutePDF (Quiet Mode)"
NomDeLaBarre = "MyCutePDF"
NomMacro = "Converttopdf_Silent"
NomClasseur = "Module1" 'GhostScript Api's
CheminEtNomImage = Application.Path & "\BITMAPS\CutePDf\Icon_Pdf_2.bmp"
'Charge l'icone du bouton
Set picImage = LoadPicture(CheminEtNomImage)
Set LaBarre = Application.CommandBars(NomDeLaBarre)
'Ajoute le bouton à la barre d'outils personnalisée
Set LeBouton = LaBarre.Controls.Add(Type:=msoControlButton)
LeBouton.FaceId = 0
LeBouton.Caption = ActionDubouton 'info-bulle du bouton
LeBouton.OnAction = NomClasseur & "." & NomMacro
'Collage de l'image sur le bouton
LeBouton.Picture = picImage
Set LaBarre = Nothing
Set LeBouton = Nothing
End Sub
Sub Demarrer_UserForm_PSTOPDF()
Application.OnTime Now + TimeValue("0:0:01"), "MiseAJour_UserForm_PSTOPDF"
End Sub
Sub MiseAJour_UserForm_PSTOPDF()
If UserForm1.ProgressBar1.Value = Duree_Gsapi_Convert Then
UserForm1.ProgressBar1.Value = 1
Else
UserForm1.ProgressBar1.Value = UserForm1.ProgressBar1.Value + 1
UserForm1.Label1 = UserForm1.Label1 + 1
End If
UserForm1.Repaint
Call Demarrer_UserForm_PSTOPDF
End Sub
' ***********************************************************
' *
' * Lance le programme par défaut associé à un fichier (en fonction de son
' * extension ) et retourne le hWnd de la fênetre du programme lançé.
' *
' ***********************************************************
Public Function OpenProgram(ByRef Filename As String, ByRef OwnerhWnd As Long) As Long
Dim SEI As SHELLEXECUTEINFO
On Error GoTo ErrorHandler
'Vérifie si le fichier à lancer est un exécutable (.exe)
If GetExtension(Filename) = "exe" Then
If vbNo = MsgBox("ATTENTION, êtes-vous sûr de vouloir lancer ce programme exécutable ?", vbExclamation + vbYesNo) _
Then
OpenProgram = 0
Exit Function
End If
End If
With SEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_FLAG_NO_UI
.hWnd = OwnerhWnd
.lpVerb = "open"
.lpFile = Filename
.lpParameters = vbNullChar
.lpDirectory = vbNullChar
.nShow = SW_SHOW
.hInstApp = OwnerhWnd
End With
OpenProgram = ShellExecuteEx(SEI)
If SEI.hInstApp <= 32 Then
'Erreurs
OpenProgram = 0
Select Case SEI.hInstApp
Case SE_ERR_FNF
OpenProgram = SEI.hProcess
Case SE_ERR_PNF
MsgBox "Le chemin du fichier à ouvrir est incorrect.", vbExclamation
Case SE_ERR_ACCESSDENIED
MsgBox "Accès au fichier refusé.", vbExclamation
Case SE_ERR_OOM
MsgBox "Mémoire insuffisante.", vbExclamation
Case SE_ERR_DLLNOTFOUND
MsgBox "Dynamic-link library non trouvé.", vbExclamation
Case SE_ERR_SHARE
MsgBox "Le fichier est déjà ouvert.", vbExclamation
Case SE_ERR_ASSOCINCOMPLETE
MsgBox "Information d'association du fichier incomplète.", vbExclamation
Case SE_ERR_DDETIMEOUT
MsgBox "Opération DDE dépassée.", vbExclamation
Case SE_ERR_DDEFAIL
MsgBox "Opération DDE echouée.", vbExclamation
Case SE_ERR_DDEBUSY
MsgBox "Opération DDE occupée.", vbExclamation
Case SE_ERR_NOASSOC
'Ouvrir avec...
Call Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " + Filename, vbNormalFocus)
End Select
Else
'Retourne le hWnd du programme lançé par ShellExecuteEx
OpenProgram = SEI.hProcess
End If
Exit Function
ErrorHandler:
OpenProgram = 0
End Function
' ***********************************************************
' *
' * Ferme un programme à partir du hWnd de sa fenêtre.
' *
' ***********************************************************
Public Function CloseProgram(hWnd As Long) As Boolean
Dim lExitCode As Long
If hWnd = 0 Then
Exit Function
End If
On Error Resume Next
CloseProgram = CBool(TerminateProcess(hWnd, lExitCode))
'On Error Resume Next
CloseHandle hWnd
DoEvents
Sleep (100)
End Function
Public Function GetExtension(Filename As String) As String
Dim tablo() As String
tablo = Split(Filename, ".")
GetExtension = tablo(UBound(tablo))
End Function |
Partager