×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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.

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

The shell command might work as you can specify the window type:

Quote:

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

https://docs.microsoft.com/en-us/office/vba/langua...

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) 

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

(OP)
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.

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

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.

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

Or investigate ShellExecute, either the API, or the Method that wraps the API in the Microsoft Shell Controls and Automation library

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

(OP)
Andy, I copied your short code and replaced strDocPath with my variable strInput. Changed nothing else and the file doesn't open. Any ideas?

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

New Form, one command button, this code (works for me):

CODE

Option Explicit

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

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

Shows SomeWordDoc.docx from location C:\MyFolder\Word


---- Andy

There is a great need for a sarcasm font.

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

(OP)
Thanks. It seems to work for Word but not for .pdf. Do you find the same thing?

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

(OP)
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.

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

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'

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

Quote (TheresAlwaysAWay)

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.

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

>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.

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

(OP)
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!

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

"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. smile


---- Andy

There is a great need for a sarcasm font.

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

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:https://www.devhut.net/2013/12/04/vba-open-a-pdf-t...

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 https://www.devhut.net/2013/12/04/vba-open-a-pdf-to-a-specific-page/
'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 

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

(OP)
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

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

(OP)

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!

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

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'.

Quote (Andrzejek)

G = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & strDocPath, vbNormalFocus)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close