Results 1 to 18 of 18

Thread: SendKeys "+" for opening PDF

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    6

    SendKeys "+" for opening PDF

    Hi guys, I have an issue with opening pdf documents. I have an tool, with an button when the button is pressed an vbs script run. In the script i have the following for opening pdf docs:

    Case "PDF"
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run "AcroRd32.exe " & cFileName, 1

    But when you click on the button adobe will open and stay in the background. When I press shift and the press the button the pdf document will be openend with adobe.Is there a way to open the pdf document without pressing the Shift key first? I have tried to add the following line but it did not help:
    WshShell.SendKeys "+"


    Does anyone have a good tip for me?

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,758

    Re: SendKeys "+" for opening PDF

    If the filename extension (i.e. pdf) is registered to open with Adobe, then open using the process class....

    Code:
    System.Diagnostics.Process.Start(cFileName)
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    6

    Re: SendKeys "+" for opening PDF

    Hi Kebo thanks for your anwer, the pdf is registered to open with adobe. But I have no idea how to put this in the vbs file top open using the process class

  4. #4
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,758

    Re: SendKeys "+" for opening PDF

    If the only thing the script does is open the pdf, then don't call the script. Instead use the code I posted. If you don't think that will work, then please post your VB code.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    6

    Re: SendKeys "+" for opening PDF

    This is the code:

    Sub Main ()

    Dim objFSO
    Dim strMediaPath
    Dim cFileName
    Dim strFspPath
    Dim CadView
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    ' Old text of ViewDoc:
    vsa.GetFieldValue "DocFileName", cFileName


    If not objFSO.FileExists( cFileName ) Then
    vsa.GetRegistryKeyValue "MEDIAPATH", strMediaPath
    cFileName = strMediaPath & "\"&cFileName

    If not objFSO.FileExists( cFileName ) Then
    vsa.GetFieldValue "DocFileName", cFileName
    vsa.GetFieldValue "FspPath", strFspPath
    cFileName = StrFspPath & cFileName

    If not objFSO.FileExists( cFileName ) Then
    vsa.MsgBox cFileName & " not found."
    Exit Sub
    End If
    End If
    End If

    Set objFSO = Nothing

    If cFileName<> "" Then
    FileExt = UCase(Right(cFileName,3))

    Select Case(FileExt)
    Case "TML", "JPG", "GIF", "AVI", "PCD", "BMP", "CMP", "TIF"
    vsa.View cFileName

    '--- Acrobat reader version 7 or higher

    Case "TXT"
    Set WshShell = CreateObject ("WScript.Shell")
    WshShell.Run "notepad.exe " & cFileName , 1
    Case "PDF"
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run "AcroRd32.exe " & cFileName, 1
    WshShell.SendKeys "+"

    End Select
    End If

  6. #6
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,758

    Re: SendKeys "+" for opening PDF

    When you call Process.Start(<fileName>), and the fileName is a valid file with a registered extension, the file will open in the application it is registered with. That means that everywhere you are calling your script, you can simply start the process instead.
    So all of this...
    Code:
    Select Case(FileExt)
    Case "TML", "JPG", "GIF", "AVI", "PCD", "BMP", "CMP", "TIF"
    vsa.View cFileName
    
    '--- Acrobat reader version 7 or higher	
    
    Case "TXT"
    Set WshShell = CreateObject ("WScript.Shell")
    WshShell.Run "notepad.exe " & cFileName , 1
    Case "PDF"
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run "AcroRd32.exe " & cFileName, 1
    WshShell.SendKeys "+"
    
    End Select
    becomes this....
    Code:
    vsa.View cFileName
    Process.Start(cFileName)
    You should see that see results provided that the only thing the script does is open the file.

    Edit...
    The code you post should not have even compiled because you have a line of code in the select case statement, but not in a case of the select (i.e. vsa.View cFileName)
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    6

    Re: SendKeys "+" for opening PDF

    Name:  1.PNG
Views: 860
Size:  7.8 KB

    with this code i am getting this error

  8. #8
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,758

    Re: SendKeys "+" for opening PDF

    with this code i am getting this error
    With what code? Other than post 5, you didn't post any. If you are getting errors, you have to post the code and indicate on which line you get the error. Without that I can't help.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  9. #9
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,168

    Re: SendKeys "+" for opening PDF

    If you want to open a PDF why not use the Webbrowser control and navigate to it ? You can save the PDF in a Special Folder on the End user's machine, and call it into the webbrowser control - or you can enter any file path -

    Its something that some people don't understand a webbrowser is the same thing as a file browser only difference is they navigate IP addresses changed through a DNS system to point to a domain like google.com

    It's the same kinda process.

    Basically you need to navigate the file - something like this, or you can use File://

    Code:
    C://Users/User/Documents/Document.pdf
    Since no one mentioned it, you can also be sure to put any code you wanna share in code brackets its hard to tell where it begins and stops:

    [code][/code]

    You can also use a file browser to open a file into a webbrowser control.

    Good luck!
    Disclaimer: When code is given for example - it is merely a example.




    Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    6

    Re: SendKeys "+" for opening PDF

    I am getting the error with this code:


    Sub Main ()

    Dim objFSO
    Dim strMediaPath
    Dim cFileName
    Dim strFspPath
    Dim CadView
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    ' Old text of ViewDoc:
    vsa.GetFieldValue "DocFileName", cFileName


    If not objFSO.FileExists( cFileName ) Then
    vsa.GetRegistryKeyValue "MEDIAPATH", strMediaPath
    cFileName = strMediaPath & "\"&cFileName

    If not objFSO.FileExists( cFileName ) Then
    vsa.GetFieldValue "DocFileName", cFileName
    vsa.GetFieldValue "FspPath", strFspPath
    cFileName = StrFspPath & cFileName

    If not objFSO.FileExists( cFileName ) Then
    vsa.MsgBox cFileName & " kan niet worden gevonden."
    Exit Sub
    End If
    End If
    End If

    Set objFSO = Nothing

    If cFileName<> "" Then
    FileExt = UCase(Right(cFileName,3))

    vsa.View cFileName
    Process.Start(CFileName)

    End If
    End Sub


    Quote Originally Posted by kebo View Post
    With what code? Other than post 5, you didn't post any. If you are getting errors, you have to post the code and indicate on which line you get the error. Without that I can't help.

  11. #11
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,758

    Re: SendKeys "+" for opening PDF

    Wait... is that vb.net code? If not, you're in the wrong forum I'm afraid.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  12. #12
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,168

    Re: SendKeys "+" for opening PDF

    Quote Originally Posted by don74 View Post
    I am getting the error with this code:


    Sub Main ()

    Dim objFSO
    Dim strMediaPath
    Dim cFileName
    Dim strFspPath
    Dim CadView
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    ' Old text of ViewDoc:
    vsa.GetFieldValue "DocFileName", cFileName


    If not objFSO.FileExists( cFileName ) Then
    vsa.GetRegistryKeyValue "MEDIAPATH", strMediaPath
    cFileName = strMediaPath & "\"&cFileName

    If not objFSO.FileExists( cFileName ) Then
    vsa.GetFieldValue "DocFileName", cFileName
    vsa.GetFieldValue "FspPath", strFspPath
    cFileName = StrFspPath & cFileName

    If not objFSO.FileExists( cFileName ) Then
    vsa.MsgBox cFileName & " kan niet worden gevonden."
    Exit Sub
    End If
    End If
    End If

    Set objFSO = Nothing

    If cFileName<> "" Then
    FileExt = UCase(Right(cFileName,3))

    vsa.View cFileName
    Process.Start(CFileName)

    End If
    End Sub
    Bro, if you listen You can solve it quickly.

    Look here: http://www.vbforums.com/showthread.p...-page-file-etc
    Disclaimer: When code is given for example - it is merely a example.




    Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  13. #13
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,168

    Re: SendKeys "+" for opening PDF

    Quote Originally Posted by kebo View Post
    Wait... is that vb.net code? If not, you're in the wrong forum I'm afraid.
    It should be. May call a mod in to assess to make sure, but it should be vb.net it looks like it anyways.
    Disclaimer: When code is given for example - it is merely a example.




    Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  14. #14
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,758

    Re: SendKeys "+" for opening PDF

    It should be.
    I'm not sure with this code....
    Code:
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    ' Old text of ViewDoc:
    vsa.GetFieldValue "DocFileName", cFileName
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  15. #15
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,168

    Re: SendKeys "+" for opening PDF

    Quote Originally Posted by kebo View Post
    I'm not sure with this code....
    Code:
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    ' Old text of ViewDoc:
    vsa.GetFieldValue "DocFileName", cFileName
    You are right its vbScript I reported to a mod so it can be moved.
    Disclaimer: When code is given for example - it is merely a example.




    Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  16. #16
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: SendKeys "+" for opening PDF

    Thread moved. The OP did say that it was VBScript, at least once.
    My usual boring signature: Nothing

  17. #17
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,758

    Re: SendKeys "+" for opening PDF

    Quote Originally Posted by Shaggy Hiker View Post
    The OP did say that it was VBScript, at least once.
    Yea he did. I was under the impression he was calling an external script for some reason.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  18. #18

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    6

    Re: SendKeys "+" for opening PDF

    Quote Originally Posted by jdc20181 View Post
    Bro, if you listen You can solve it quickly.

    Look here: http://www.vbforums.com/showthread.p...-page-file-etc

    Thanks bro, but i am uber nood and i have no idea how to use this....

Posting Permissions

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



Click Here to Expand Forum to Full Width