Notifications
Clear all

Comando VBA para fechar pdf

3 Posts
3 Usuários
0 Reactions
2,075 Visualizações
 caje
(@caje)
Posts: 97
Trusted Member
Topic starter
 

Gostaria de saber se existe algum comando no vba para fechar um PDF especifico.

Exemplo.: ao rodar a Macro gostaria que esta rotina fechasse o arquivo teste.pdf

Se alguem tiver alguma dica Agradeço

 
Postado : 11/04/2014 7:13 pm
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa noite!!
Não testado....tente adaptar.

Sub AleVBA_11291()
    AleVBA ("C:UsersusernameDesktopArquivo.pdf")
End Sub

Sub AleVBA(FileName As String)
    Dim iFilenum As Long
    Dim iErr As Long, IsFileOpen As Boolean
      
    On Error Resume Next
    iFilenum = FreeFile()
    Err.Clear
    Open FileName For Input Lock Read As #iFilenum
    Close iFilenum
    iErr = Err.Number
    On Error GoTo 0
      
    Select Case iErr
    Case 0:    IsFileOpen = False
    Case 70:   IsFileOpen = True
    Case Else: Error iErr
    End Select
      
    If IsFileOpen Then
        Close #iFilenum
    End If
End Sub

Att

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 11/04/2014 7:36 pm
Basole
(@basole)
Posts: 487
Reputable Member
 

caje,
Se estiver usando o acrobat reader isso deve funcionar:

Option Explicit

Private Const WM_CLOSE = &H10
Private Const INFINITE = &HFFFFFFFF

Private Declare Function apiPostMessage _
    Lib "user32" Alias "PostMessageA" _
    (ByVal Hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) _
    As Long

Private Declare Function apiFindWindow _
    Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassname As String, _
    ByVal lpWindowName As String) _
    As Long
    
Private Declare Function apiWaitForSingleObject _
    Lib "kernel32" Alias "WaitForSingleObject" _
    (ByVal hHandle As Long, _
    ByVal dwMilliseconds As Long) _
    As Long
    
Private Declare Function apiIsWindow _
    Lib "user32" Alias "IsWindow" _
    (ByVal Hwnd As Long) _
    As Long
        
Private Declare Function apiGetWindowThreadProcessId _
    Lib "user32" Alias "GetWindowThreadProcessId" _
    (ByVal Hwnd As Long, _
    lpdwProcessID As Long) _
    As Long

Function fCloseApp(lpClassname As String) As Boolean

Dim lngRet As Long, Hwnd As Long, pID As Long

    Hwnd = apiFindWindow(lpClassname, vbNullString)
    If (Hwnd) Then
        lngRet = apiPostMessage(Hwnd, WM_CLOSE, 0, ByVal 0&)
        Call apiGetWindowThreadProcessId(Hwnd, pID)
        Call apiWaitForSingleObject(pID, INFINITE)
        fCloseApp = Not (apiIsWindow(Hwnd) = 0)
    End If
End Function

Sub Exemplo()
        fCloseApp ("AcrobatSDIWindow")
End Sub

Click em se a resposta foi util!

 
Postado : 11/04/2014 8:12 pm