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
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
You can use the Dir function with a wildcard extension to return the name of the file.
 

Domski

Well-known Member
Joined
Jan 18, 2005
Messages
7,292
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
 

nehpets12

Active Member
Joined
Feb 22, 2002
Messages
453
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,232
Messages
5,594,962
Members
413,954
Latest member
mrsandy

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
Top