How to open PDF, Text, Word, etc files using VBA in Excel. Watch the video below:
An easy way to open a file is to open the file explorer and double click on a file. The file is automatically opened because Windows knows the file extension and the associated program to open the file. See the image below:
We can automate this process of opening a file via Excel VBA using the following macro code:
VBA.Shell “Explorer.exe C:\Diya-David Lowenthall SEC.pdf”, vbNormalFocus ‘Active line of code
‘VBA.Shell “Explorer.exe C:\Users\takyar\Documents\confucianism-how-it-framed-chinese-economy-society-culture-polity.docx”, vbMaximizedFocus
‘VBA.Shell “Explorer.exe C:\ETV-22-09-2021\excel-training-videos-16\simple-calculation-using-IF.xlsx”, vbNormalFocus
‘VBA.Shell “Explorer.exe C:\Users\takyar\Documents\cleaning-tank.txt”, vbMaximizedFocus
Some of the VBA code lines have been remarked out using an apostrophe. If you remove the apostrophe the line of code becomes active i. e gets executed on running the macro.