Save PDF to a folder using VBA
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Save PDF to a folder using VBA

  1. #1
    Board Regular
    Join Date
    Jun 2017
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Save PDF to a folder using VBA

    Hello guys,

    I tried to search about this around here, but couldn't find anything.

    I have downloaded a PDF file from SAP, and I just need to save the PDF to a specific folder in my computer.
    How can I do this? I tried some solutions found on internet but none of them really worked.

    Thanks

  2. #2
    New Member
    Join Date
    Nov 2015
    Posts
    33
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save PDF to a folder using VBA

    when you say you downloaded a pdf file from sap, where does it go? why do you need excel to save it again. not understanding what you want done.

  3. #3
    Board Regular
    Join Date
    Jun 2017
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save PDF to a folder using VBA

    Quote Originally Posted by Danmc View Post
    when you say you downloaded a pdf file from sap, where does it go? why do you need excel to save it again. not understanding what you want done.
    The file stays in "C:\Temp", I need to save to another folder

  4. #4
    New Member
    Join Date
    Nov 2015
    Posts
    33
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save PDF to a folder using VBA

    so you save the file in SAP. then you go to excel. you press a button and file copies to new location. is that correct?

  5. #5
    Board Regular
    Join Date
    Jun 2017
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save PDF to a folder using VBA

    Quote Originally Posted by Danmc View Post
    so you save the file in SAP. then you go to excel. you press a button and file copies to new location. is that correct?
    Yes. My file is in SAP, I double-click to open the PDF file with Adobe Reader. I Have already managed to move the file from Temp to my folder, but now I would like also to close the PDF file, Idk if that's possible.

    Tell me if you have anything even better

  6. #6
    New Member
    Join Date
    Nov 2015
    Posts
    33
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save PDF to a folder using VBA

    still confused. you download a PDF (from SAP) into your temp folder and the PDF is open, correct?
    you want to press a button in excel to copy from c:\temp to c:\YourFolder, yes? (that can be done as long as you know the filename (which folder is it going to?))

    as for killing Acrobat Reader, you can do something like the following

    Code:
    Dim oServ AsObject
    Dim cProc AsVariant
    Dim oProc AsObject
    
    Set oServ = GetObject("winmgmts:")
    Set cProc = oServ.ExecQuery("Select * from Win32_Process")
    
    ForEach oProc In cProc
    
        'Rename EXCEL.EXE in the line below with the process that you need to Terminate. 
        'NOTE: It is 'case sensitive
    
        If oProc.Name ="AcroRd32.exe"Then
          'MsgBox "KILL"' used to display a message for testing pur
          oProc.Terminate()
        EndIf
    Next

  7. #7
    Board Regular
    Join Date
    Jun 2017
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save PDF to a folder using VBA

    Quote Originally Posted by Danmc View Post
    still confused. you download a PDF (from SAP) into your temp folder and the PDF is open, correct?
    you want to press a button in excel to copy from c:\temp to c:\YourFolder, yes? (that can be done as long as you know the filename (which folder is it going to?))

    as for killing Acrobat Reader, you can do something like the following

    Code:
    Dim oServ AsObject
    Dim cProc AsVariant
    Dim oProc AsObject
    
    Set oServ = GetObject("winmgmts:")
    Set cProc = oServ.ExecQuery("Select * from Win32_Process")
    
    ForEach oProc In cProc
    
        'Rename EXCEL.EXE in the line below with the process that you need to Terminate. 
        'NOTE: It is 'case sensitive
    
        If oProc.Name ="AcroRd32.exe"Then
          'MsgBox "KILL"' used to display a message for testing pur
          oProc.Terminate()
        EndIf
    Next
    I managed to do what i wanted.

    First, I get the hwnd name and then move the pdf file to my folder.

    Here I get the pdf filename:
    Code:
    Public Function getNameFromHwnd(hwnd As Long) As String
    Dim title As String * 255
    Dim tLen As Long
    tLen = GetWindowTextLength(hwnd)
    GetWindowText hwnd, title, 255
    getNameFromHwnd = Left(title, tLen)
    
    Name = Split(getNameFromHwnd, " -")
    name_pdf = Name(0)
    End Function
    and here I move the pdf file:
    Code:
    Sub movePDF(ByRef RC_num As String)
    
    sourcePath = "C:\Temp"  'Change path and folder name to suit
    destPath = "C:\Users\est.rodrigojf\Documents\SAP\RC " & RC_num  'Change path and folder name to suit
    
    hwnd = FindWindow("AcrobatSDIWindow", vbNullString)
    FileCopy sourcePath & "\" & name_pdf, destPath & "\" & name_pdf
    Anyway, thanks for helping, really like you guys!

  8. #8
    New Member
    Join Date
    Nov 2015
    Posts
    33
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save PDF to a folder using VBA

    if this fixed the issue for you, please mark the thread as solved and please thank or like me if i helped you in any way.

  9. #9
    Board Regular
    Join Date
    Jun 2017
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save PDF to a folder using VBA

    Quote Originally Posted by Danmc View Post
    if this fixed the issue for you, please mark the thread as solved and please thank or like me if i helped you in any way.
    Sorry, bu I don't know how to mark as solved.

  10. #10
    New Member
    Join Date
    Nov 2015
    Posts
    33
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save PDF to a folder using VBA

    goto the top of the post. click 'Thread Tools', choose Solved. then thank me (under my post name) if your happy with the service

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •