How do I open a non excel file from within VBA?

DipDip

Board Regular
Joined
Jan 23, 2015
Messages
76
Office Version
  1. 2016
Platform
  1. Windows
Hi all,
So I'm using a userform to open a particular file via a vlookup from 2 combobox inputs. However, it won't work with non excel files. Can anyone help me with this?

I use the following code:

Code:
Private Sub OkButton_Click()
Dim loc As Variant
loc = Application.VLookup(Me.ComboBox2.Value, Sheets("Locations").Range("B2:c2525"), 2, True)
Workbooks.Open (loc)

However, some of the files are Word documents & Publisher files and obviously workbooks.open won't let you do this. Is there a way that it will open the file from the cell reference irrespective of what type of file it is?

Thanks in advance for any help anyone can give me.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Cheers for that. However I plan to add a print function to this. The idea being that in a text box they type how many copies they'd like printed of the file. Would this still work with this code? Or does it need to be done another way?
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,616
Latest member
intern444

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