Open unknown file type

nehpets12

Active Member
Joined
Feb 22, 2002
Messages
453
Using vba how do I open a file if I dont know what it is saved as?
It can be a pdf jpeg doc or xls

This is what I use to open a pdf

Code:
 myfile = "U:\Personnel Records\Training\" & Cells(1, ActiveCell.Column).Value & "\" & Format(Cells(ActiveCell.Row, 1).Value, "0000") & ".pdf"

ActiveWorkbook.FollowHyperlink Address:=myfile, NewWindow:=True, AddHistory:=True

Thank you in advance
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Maybe:
Code:
myfile = Dir("U:\Personnel Records\Training\" & Cells(1, ActiveCell.Column).Value & "\" & Format(Cells(ActiveCell.Row, 1).Value, "0000") & ".*")

If myfile <> "" Then


ActiveWorkbook.FollowHyperlink Address:=myfile, NewWindow:=True, AddHistory:=True


End If

Dom
 
Upvote 0
This works brilliantly on a file that it can open :)
In my folder I have a number of files with the same no but differant file extentions it trys to open the first one but stops because there is no program to open it
Example

032409.000
032409.001
032409.dwg
032409.pdf

How can I loop the code to open the files that it can open
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top