Microsoft Excel - Open Excel Workbook - Asked By Dan on 01-Feb-16 12:41 PM

So I have several Excel workbooks on a server and I am trying to figure out how to open them using a drop down list from my main Excel workbook.


On the sheet UPDATE in my main workbook in cells C10:E10 is the drop down list


I have the code to open a workbook, but not one that can take a name from the drop down list in cells C10:E10


Workbooks.Open Filename:="P:\People\Bob.xlsx", ReadOnly:=True


Example of workbooks


Bob.xlsx

Mike.xlsx

Steve.xlsx

linda.xlsx


Any help would be greatly appreciated.


Dan

Harry Boughen replied to Dan on 01-Feb-16 02:21 PM
Hello Dan

Assuming that your dropdown cell is A1 then using "P:\People\"&Range("A1").Value should go some way to getting your where you want to be.

Harry
Dan replied to Harry Boughen on 01-Feb-16 04:09 PM
Nope, I have tied that
Harry Boughen replied to Dan on 01-Feb-16 05:09 PM
Hi dan,

Try something like this and see if it makes a difference.


PathName = "P:\People\"
Filename = Range("A1").Value
Workbooks.Open Filename:=PathName & Filename, ReadOnly:=True

Harry
Dan replied to Harry Boughen on 02-Feb-16 12:19 PM

So, I am get the error


        Run-time "1004':

        Method "Open" of object "Workbooks" failed

Harry Boughen replied to Dan on 02-Feb-16 02:38 PM
Hello Dan,

Have you tried it without the ReadOnly:=True to see if that makes a difference?

The other thing is, are you sure that your path is transcribed completely and accurately and ditto for your list of file names eg no hidden characters or leading spaces etc?

Another suggestion seems to be that the file is somehow corrupt.  Does it occur on all files?  Can you open the file manually?  Try doing a SaveAs under another name (say Boba.xls), change your list to the new name and try again.  If it then works, reverse the process to the original name(s).

I have not had any problems with that code in testing.

Harry
Harry Boughen replied to Dan on 03-Feb-16 01:29 AM
Hello Dan,

I did a bit more research on this after I realised you were working on a server whereas I am only working locally.

Have a read of this page.  There might be something of use there.

http://dedicatedexcel.com/universal-network-drive-mapping-with-excel-2010-vba/

Harry