Hello, I have a master sheet (Called daily report) which has a macro to call other excel sheets to open within the same folder.
The folder is on a shared directory (P for me) and the problem i have is that the letter of the directory is different on other people's computers.
Is there a better way of coding the below so the macro will work without having to state the folder directory letter?
By the way, this is just the beginning of the macro - the remainder is irrevlevant to my request.
Code:Application.ScreenUpdating = False Workbooks.Open Filename:= _ "P:\Schedules\so.xlsx" Workbooks.Open Filename:= _ "P:\Schedules\mrp.xlsx" Workbooks.Open Filename:= _ "P:\Schedules\orders.xlsx" Workbooks.Open Filename:= _ "P:\Schedules\otd.xlsx" Workbooks.Open Filename:= _ "P:\Schedules\financial.xlsx" Workbooks.Open Filename:= _ "P:\Schedules\inventory.xlsx" Windows("Daily Report.xlsx").Activate
There are a couple of things I can think of. The easiest and most reliable would be to use an .inputbox to have a user type in the drive letter or an application.getopenfilename to select the first file, then get the drive and folder name from that.
If that is not an option, the below code will go through each drive A:\ to Z:\ and search for the first file you list in your code above. Once found, it will make the variable strFound equal to that DRIVE (ex: P:\)
After putting this code first, you'd have to alter the rest of your code to use strFound:Code:Public Sub FindDirectory() Dim strDrive As String Dim strPath As String Dim strFound As String For i = 1 To 26 strDrive = Chr(i + 64) & ":/" strPath = strDrive & "Schedules/so.xlsx" If Dir(strPath) > "" Then strFound = strDrive End If Next i End Sub
Code:Workbooks.Open Filename:= _ strFound & "Schedules\so.xlsx" Workbooks.Open Filename:= _ strFound & "Schedules\mrp.xlsx" ...
Is your code running too slowly?
Does your workbook or database have a bunch of duplicate pieces of data?
Have a look at this article to learn the best ways to set up your projects.
It will save both time and effort in the long run!
Dave
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks