Forum Discussion
Excel hyperlink default software to open FileName .pdf
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!
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:
- Open the VBA Editor:
- Press Alt + F11.
- Insert a New Module:
- In the VBA editor, go to Insert > Module.
- 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
Sub OpenPDFfromCell()
Dim filePath As String
filePath = ThisWorkbook.Sheets("Sheet1").Range("A1").Value ' Adjust the range as needed
OpenPDF filePath
End Sub- Use the Macro:
- You can use the OpenPDFfromCell macro to open a PDF file whose path is specified in cell A1 of "Sheet1". Adjust the cell reference as needed.
- Assign the Macro to a Button (Optional):
- Go to the Developer tab, click on Insert, choose Button (Form Control), draw the button on your sheet, and assign the OpenPDFfromCell macro to it.
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:
- Open Registry Editor:
- Press Windows + R, type regedit, and press Enter.
- Navigate to the Key for PDF File Associations:
- Go to HKEY_CLASSES_ROOT\.pdf.
- Verify or Modify the Default Value:
- Ensure that the (Default) value points to the correct file association. This should match the application set in your Default Apps settings.
- Navigate to the Key for the Application:
- Go to HKEY_CLASSES_ROOT\Applications\ and find your preferred PDF application.
- Verify Command Settings:
- Check if the command under shell\open\command is correct for your preferred PDF application.
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:
- Open Command Prompt as Administrator:
- Press Windows + X and choose Command Prompt (Admin) or Windows PowerShell (Admin).
- Run the Following Command:
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
- Update Excel: Ensure that your Excel is updated to the latest version.
- Check for Conflicting Software: Sometimes third-party software or PDF viewers might conflict with the default settings.
- Reinstall the PDF Viewer: Uninstalling and reinstalling your preferred PDF viewer might reset and enforce the default file associations.
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.