Consulting

Results 1 to 8 of 8

Thread: PDF tow Excel

  1. #1
    VBAX Regular
    Joined
    Jan 2011
    Posts
    55
    Location

    PDF tow Excel

    Dear Forum,

    I want to apply external command but its not working for me, It seams the VBA is not selecting the data from the desired location!!

    in the attached file, VBA copiying its oun code text!!

    PLz let me know the mistake behinde,

    BR a
    amrane
    Attached Files Attached Files

  2. #2

  3. #3
    VBAX Regular
    Joined
    Jan 2011
    Posts
    55
    Location

    Wink PDF tow Excel

    Dear mohanvijay

    Thank you so much for your reply,
    Its seams its ,not possible to execut VBA code including "step-per-step" the only way is to run it complet code, so am I correct, is there any way to recover this limitation?

    Thank you sir,
    amrane

    Sub SendKeysExample()
    Dim AppID As Variant
    AppID = Shell("C:\Windows\notepad.exe", 1)
    AppActivate AppID
    SendKeys "Hello", True
    SendKeys "~", True
    SendKeys "world", True
    End Sub

  4. #4
    VBAX Regular
    Joined
    Jan 2011
    Posts
    55
    Location

    PDF tow Excel (crrection)

    dear mohanvijay,

    I am sorry I missed to writ code including "Sendkey statement as per the below code:
    Sub SendKeysExample()
    Dim AppID As Variant
    AppID = Shell("C:\Windows\notepad.exe", 1)
    AppActivate AppID
    SendKeys "Hello", True
    SendKeys "~", True
    SendKeys "world", True
    End Sub

    BR
    amrane

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Amrane, what is your goal? Using SendKeys() to accomplish a goal is seldom a good idea. It should only be considered as a last resort. If your goal is to write to Notepad, there are several methods besides SendKeys() to do that.

    As Mohanvijay said, IF you have Adobe Acrobat and not just the Reader, you can use the method that he posted to get text from a PDF file.

    There are two basic issues with SendKeys: (1) focus, and (2) timing. While you can use a Wait method as you did to wait for focus to be set, there is no assurance that sufficient time was set. While I used your Wait method here, a better method is to Loop Until the active window is the window that is needed. A spy program can you show you Window caption title and class names.

    e.g. In a Module:
    [vba]Option Explicit

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
    ByVal lpsz2 As String) As Long

    Private Declare Function Putfocus Lib "user32" Alias "SetFocus" _
    (ByVal hwnd As Long) As Long


    Sub Shell_Copy_Paste()
    Dim Pdf_file As Variant
    Dim wkSheet As Worksheet
    Dim xlmain As Long, xldesk As Long, excel As Long

    Pdf_file = Shell("cmd /c x:\pdf\sheet2.pdf", vbNormalFocus)

    Application.Wait (Now + TimeSerial(0, 0, 2)) 'Wait for Acrobat to load

    SendKeys "^a", True 'Select All
    SendKeys "^c", True 'Copy
    SendKeys "%{F4}", True 'Close shell application

    ' www.patorjk.com, free spy program
    xlmain = FindWindow("xlmain", vbNullString)
    xldesk = FindWindowEx(xlmain, 0&, "xldesk", vbNullString)
    excel = FindWindowEx(xldesk, 0&, "excel7", vbNullString)
    Putfocus excel

    Range("B5").PasteSpecial xlPasteAll
    Range("B5").Select
    End Sub[/vba]

    Another big problem with SendKeys() is that in Vista+, you need to disable UAC for it to work.

  6. #6
    VBAX Regular
    Joined
    Jan 2011
    Posts
    62
    Location
    Quote Originally Posted by mohanvijay

    Hi mohanvijay,

    i download the attached sheet when i click on the form button get an error "Active X component cannot create object " please help i really need of this file for my work better.

    thanks
    farrukh

  7. #7
    VBAX Tutor mohanvijay's Avatar
    Joined
    Aug 2010
    Location
    MADURAI
    Posts
    268
    Location
    do you have Adobe Acrobat or just Adobe Reader?

    You must need Adobe Acrobat to run that macro

  8. #8
    VBAX Regular
    Joined
    Jan 2011
    Posts
    62
    Location
    Thanks mohanvijay for your reply , i have only reader not complete version of acrobat . I will install full version of Adobe Acrobat professional version 7.0 and run ?

    Thanks
    farrukh

Posting Permissions

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