PDA

View Full Version : PDF tow Excel



amrane
02-14-2012, 08:26 AM
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

mohanvijay
02-14-2012, 08:45 PM
Check this KB

http://www.vbaexpress.com/kb/getarticle.php?kb_id=1101

amrane
02-15-2012, 01:08 AM
Dear mohanvijay (http://www.vbaexpress.com/forum/member.php?u=36127)

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:dunno, 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

amrane
02-15-2012, 01:11 AM
dear mohanvijay (http://www.vbaexpress.com/forum/member.php?u=36127),

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

Kenneth Hobs
02-15-2012, 08:13 AM
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:
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 (http://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

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

farrukh
02-17-2012, 12:32 PM
Check this KB

http://www.vbaexpress.com/kb/getarticle.php?kb_id=1101


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

mohanvijay
02-19-2012, 03:33 AM
do you have Adobe Acrobat or just Adobe Reader?

You must need Adobe Acrobat to run that macro

farrukh
02-19-2012, 05:15 AM
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