Jul 04 2024 09:33 PM
A hyperlink to a ".pdf" type file is created in an excel cell.
Clicking on this hyperlink opens the file.
The problem is that the default software to do this is Adobe Acrobat not the default software I have set in my Settings > Apps > Default Apps.
It seems that Excel has a mind of its own when it comes to this function/action (Opening a Hyperlink to a ".pdf " file elsewhere in the computer).
This is a new recent problem as for many years the default setting was always used.
How to get excel to use the default software as it used to do? Help please!
Jul 05 2024 12:31 PM
To ensure that Excel uses the default software set in your Windows settings to open PDF files, you may need to check and adjust a few settings. Here are some steps you can take to resolve this issue:
Step 1: Verify Default App Settings in Windows
1. Open Default Apps Settings:
2. Set Default PDF Viewer:
Step 2: Check File Association for Hyperlinks in Excel
Excel should respect the default file associations set in Windows. However, if it does not, you can try the following workaround:
Step 3: Repair Office Installation
Sometimes, the issue might be due to a corruption in the Office installation. Repairing Office can fix this.
1. Open Control Panel:
2. Go to Programs and Features:
3. Repair Microsoft Office:
Step 4: Create a Custom VBA Function to Open PDFs
If the above methods do not work, you can create a custom VBA function in Excel to open PDFs using the default application. Here’s how you can do this:
1. Open the VBA Editor:
2. Insert a New Module:
3. Paste the Following Code:
Vba Code is untested backup your file.
Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Sub OpenPDF(filePath As String)
ShellExecute 0, "open", filePath, "", "", 1
End Sub
4. Use the Macro to Open PDFs:
Vba Code is untested backup your file.
Sub OpenPDFfromCell()
Dim filePath As String
filePath = ThisWorkbook.Sheets("Sheet1").Range("A1").Value ' Adjust the range as needed
OpenPDF filePath
End Sub
Step 5: Assign Macro to a Button (Optional)
1. Insert a Button:
2. Assign Macro:
By following these steps, you should be able to ensure that PDFs open with your preferred default software when clicking hyperlinks in Excel. The VBA workaround provides a custom solution that overrides Excel’s default behavior. The text, steps and code were created with the help of AI.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and Like it!
This will help all forum participants.
Jul 07 2024 03:39 AM
@NikolinoDE Hello and thank you for your reply. I had tried everything you suggested above Step 4 and nothing worked. So, I turned to Co-Pilot and asked what might be causing excel to ignore the default pdf setting. This led me to shell settings. I was getting outside my knowledge here so I did not proceed but posted my POST instead. I have used VBA and built functions so have some expertise in this area but, your coding is pushing me a bit. I will do some more work in this area as time allows. If I come up with anything useful I will let you know. Thanks again!
Jul 07 2024 04:57 AM
I understand that the steps provided initially did not solve the problem and that you're comfortable working with VBA. Since the issue persists even after following the initial steps, it might indeed be related to shell settings or registry settings in Windows that Excel might be relying on.
To dig deeper, let’s focus on ensuring that the VBA solution provided will work effectively and explore possible shell settings or registry modifications. Here’s a more detailed approach:
VBA Solution
First, let's refine the VBA solution to ensure it correctly opens the PDF with the default application:
Vba Code is untested backup your file.
Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Sub OpenPDF(filePath As String)
ShellExecute 0, "open", filePath, "", "", 1
End Sub
Sub OpenPDFfromCell()
Dim filePath As String
filePath = ThisWorkbook.Sheets("Sheet1").Range("A1").Value ' Adjust the range as needed
OpenPDF filePath
End Sub
Registry Settings
Sometimes, shell settings in the registry determine how files are opened. Here’s how you can ensure the default PDF application is set correctly:
Shell Settings
If you suspect shell settings might be affecting this, here’s a command you can run in Command Prompt to reset file associations:
Sh Code is untested.
ftype pdffile="<path_to_your_pdf_viewer_executable> %1"
Replace <path_to_your_pdf_viewer_executable> with the full path to your preferred PDF viewer executable.
Additional Considerations
By combining these methods, you should be able to get Excel to respect your default PDF viewer settings. If the issue persists, further investigation into Windows shell settings or more advanced registry tweaks might be necessary.
Jul 10 2024 03:52 AM
Hi How am I going - trying ?
I am at the end of my knowledge when I get to your VBA solution.
What does the Shell32.dll do and what are the arguments that are being pased to it?
Since there is closing bracket to the funcction declaration , are ther more arguments?
Is the function What is the significance of the “0” and the “1” in the OpenPDF sub?
My problem is making an excel hyperlink that I create in my excel file use my chosen PDF software.
Is the code intended to open my PDF App and using this dll file is the way to do this in VBA?
Your REGISTRY SETTINGS notes yield the following Screen shots.
1, 2, 3
4
5
Shell Settings Next!
Jul 10 2024 03:36 PM
Explanation of ShellExecute Function and VBA Code
The ShellExecute function in the shell32.dll library is used to perform various operations on files, such as opening them with their associated applications. This function is part of the Windows API and is commonly used in VBA to interact with the operating system.
ShellExecute Function Declaration
Vba Code is untested backup your file.
Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
VBA Code Explanation
Here is the VBA code provided earlier, with comments to explain each part:
Vba Code is untested backup your file.
' Declare the ShellExecute function from the shell32.dll library
Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
' Subroutine to open a PDF file
Sub OpenPDF(filePath As String)
' Call the ShellExecute function with parameters to open the PDF file
ShellExecute 0, "open", filePath, "", "", 1
End Sub
' Subroutine to open a PDF file whose path is specified in a cell
Sub OpenPDFfromCell()
Dim filePath As String
' Get the file path from cell A1 on Sheet1
filePath = ThisWorkbook.Sheets("Sheet1").Range("A1").Value
' Call the OpenPDF subroutine to open the PDF file
OpenPDF(filePath)
End Sub
Declare Function ShellExecute...: This line declares the external function from the Windows API.
Steps to Use the VBA Code
Ensuring Excel Uses the Default PDF Viewer
While the VBA solution provides a way to open PDFs using the default application, it's crucial to ensure that your system settings are correctly configured to use your preferred PDF viewer. Here’s how to double-check and adjust these settings:
Verify Default App Settings in Windows
Shell Settings Command
Cmd Code is untested.
ftype pdffile="C:\Path\To\Your\PDFViewer.exe %1"
Additional Steps
If you still encounter issues, consider the following additional steps:
By following these steps and using the provided VBA solution, you should be able to ensure that your Excel hyperlinks open PDFs with your preferred default application. The text, steps and codes were created with the help of AI.
My answers are voluntary and without guarantee!
Hope this will help you.
Jul 11 2024 03:02 AM
Thank you for your explanation of ShellExecute Function and VBA Code. I will work my way through your notes.
Did you have any comments on the pictures showing my registry settings?
Regards Roderick