Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Application.FollowHyperlink be forced to open pdf in Normal mode? 4

Status
Not open for further replies.

TheresAlwaysAWay

Programmer
Mar 15, 2016
135
0
0
US
I'm using Application.FollowHyperlink to open incoming faxes that are in .pdf format. Of course, they open in the default program for that filetype, which is what I want. I really can't do it any other way because different computers have Adobe Reader in different places, and some even have the full version.

Is there some way to force the documents to open in Normal mode from Application.FollowHyperlink? Right now they are always maximized and of course they cover everything else on the screen. It works perfectly otherwise. Just would like to open it in a reduced view if possible!

Thanks to everyone in advance.
 
The shell command might work as you can specify the window type:

vbNormalFocus 1 Window has focus and is restored to its original size and position.


I don't have acrobat, so this is only an example of what it might look like. You may need to put in the full path and file name for acrobat, or if it is in the path, may be able to get by with just the name.

Code:
Dim RetVal

retval = Shell("PDFProgram " & stPDFFileName, vbNormalFocus)
 
Thanks. I had seen several similar code configurations but the beauty of Application.FollowHyperlink to me is that I don't have to know which program is loaded on each workstation, where it is located, which version it is, etc. I don't even care about any of that as long as it opens the document.

I understand that Application.FollowHyperlink has limited functionality, and that I may be searching for a solution that doesn't exist. Perhaps Normal mode is beyond the capabilities of the function. I'm still hoping that somebody out there has some trick up his or her sleeve that will let me use this great, simple feature the way I'd ideally like to use it.

I really appreciate your suggestion, and I'm sure it would work. But frankly the tradeoff in convenience between just using whatever default program is on the work station and having to specify a program is just not a good bargain for me with 20 constantly-changing work stations.
 
I have this little sub that accepts a path to your (any) file and opens it with the default app associated with this type of document:

Code:
Public Sub OpenDocument(strDocPath As String)
Dim G As Long
G = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & strDocPath, vbNormalFocus)
End Sub


---- Andy

There is a great need for a sarcasm font.
 
Or investigate ShellExecute, either the API, or the Method that wraps the API in the Microsoft Shell Controls and Automation library
 
Andy, I copied your short code and replaced strDocPath with my variable strInput. Changed nothing else and the file doesn't open. Any ideas?
 
New Form, one command button, this code (works for me):

Code:
Option Explicit

Private Sub Command1_Click()
Call OpenDocument([red]"C:\MyFolder\Word\SomeWordDoc.docx"[/red])
End Sub

Public Sub OpenDocument(strDocPath As String)
Dim G As Long
G = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & strDocPath, vbNormalFocus)
End Sub

Shows [tt]SomeWordDoc.docx[/tt] from location [tt]C:\MyFolder\Word [/tt]


---- Andy

There is a great need for a sarcasm font.
 
Thanks. It seems to work for Word but not for .pdf. Do you find the same thing?
 
It seems better but not ideal. When I use your code if the last view I had open was Normal then it will reopen in Normal, but it does not actually force the view to Normal. If the last view was Maximized it reopens the same way.
 
I repeat my earlier suggestion: investigate ShellExecute. Somewhat more flexible. Having said that, the behaviour you report is anomalous; vbNormalFOcus should open a window as non-minimized or -maximized. And a quick test here confirms that - the behaviour is, however, also somewhat dependant on the default application. For example, Adobe Acrobat Reader will insist on opening the window maximised if the last known state was maximised. I mention this because you mentioned PDFs. This is the default behaviour for Acrobat - but you can change it by opening Acrobat and selecting:

Edit > Preferences > Documents and then ticking 'Restore last view settings when reopening documents'
 
TheresAlwaysAWay said:
It seems to work for Word but not for .pdf

On my computer PDFs open in Adobe Acrobat with no problem.


---- Andy

There is a great need for a sarcasm font.
 
>On my computer PDFs open in Adobe Acrobat with no problem.

get the feeling the OP did then get this working with PDFs, but then noted the anomalous behaviour of Acrobat Reader.
 
I'm always amazed by how selfless the contributors here are. You collectively puzzle over someone else's problem, write specific code to help, and just generally are a really great bunch of people. I can't tell you how much I appreciate everyone's efforts.

Regarding this specific issue, I just used Strong's advice to select Edit > Preferences > Documents and then ticking 'Restore last view settings when reopening documents'. It's working well enough for my needs.

Thank you all again. I'm giving you all a star because I want to!
 
write specific code to help"- well, not always...
If I see that someone doesn't do anything, doesn't even try, and asks: "How do I do it?" then I (we) usually ask: "What did you try and where are you stuck?" But when I see a lot of effort from OP and I may know the solution, then... why not? It makes me feel good. :)


---- Andy

There is a great need for a sarcasm font.
 
If of interest, I found code that will enable opening the pdf to a specific page which is something I was looking for and followhyperlink didn't seem to allow either. The full version of the code has more options (show/hide thumbnails, scroll bars and zoom level, etc.). I got it down to one line for posting purposes and it works. Since Reader is not my default program, I hard coded it, but I assume that substituting Andy's RUNDLL32 version would work also.
Original Code:
Note: OpenPDFtoPage1Liner the 1 does not mean Page 1, rather means 1 Liner (one line of code)

Code:
Public Sub OpenPDFtoPage1Liner(pdfname As String, pageno As Integer)
'Based on [URL unfurl="true"]https://www.devhut.net/2013/12/04/vba-open-a-pdf-to-a-specific-page/[/URL]
'20190419
    Dim retVal
    Dim stAcrobatPath As String
    
    stAcrobatPath = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
    retVal = Shell(stAcrobatPath & " /A page=" & Chr(34) & pageno & Chr(34) & " " & Chr(34) & pdfname & Chr(34), vbNormalFocus)
End Sub
 
Andy, your last line proved my point. You said that helping other people "makes you feel good".

Guess what? Feeling good about helping others is my definition of a "good person".

That's exactly what I was saying about all you guys. High fives all around. [thanks]
 

sxschech, thanks. I know what you showed will work but I have a network of 20+ work stations and the code needs to work flawlessly on all of them. There are different default programs and different paths, and that's why I was specifically asking about Application.FollowHyperlink. It doesn't care a whit about any of that, but it seems that it has limited functionality.

Although I would like to use your code or some variation of it, ultimately it just isn't worth it to me to specify the program and take the chance of possible conflicts, either now or in the future.

That's why barring a specific command that will make Application.Hyperlink do what I want it to do I am just gonna stick with Strong's suggestion of Edit > Preferences > Documents and then ticking 'Restore last view settings when reopening documents'.

It's not perfect but it's ok. Remember, this is a user convenience feature. Everything works just fine with Application.Hyperlink but I'm just trying to make the work flow a little smoother on the floor by forcing the view to Normal. That said, it just isn't worth potential headaches across the floor.

George Carlin stated my dilemma perfectly. "Never underestimate the power of stupid people in large groups." If I limit the code to something specific some day, some way, it's surely gonna blow up in my face!
 
Until I saw this post, have been using follow hyperlink, as like you, didn't want to worry about what application someone had or didn't have. I looked into this because there is one type of document we receive in pdf format in which I need to see the second page and for the default program we use, I haven't been able to find a command switch. For that reason, in my example, I hard coded the path to acrobat so it would open using reader rather than our default pdf application. As I mentioned in that thread, if you use Andy's approach, then you don't have to hard code the value and whatever program is associated with that application would be what it opens under. Of, course it still wouldn't address your other issue about the 'Restore last view settings'.

Andrzejek said:
G = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & strDocPath, vbNormalFocus)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top