Open a file without the directory name

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
Can i open a workbook without knowing the directory? more importantly without showing the directory?

I want open the file "EstimatingSheet" where ever it is.

Thank you,
Michael
 
Well, I want to start fresh with the Estimating sheet. If it does not close it has the new workbook open with the new name.

Does this make any more sense? Norie i am sorry for bieng a pain. It works fine when I list the Directories?????

Michael
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Michael

Sorry it just doesn't make sense.:)

Perhaps I'm missing something?

If you want to use the new workbook why not close the original workbook and leave the new one open?
 
Upvote 0
OK :eek:
Let me try to be clearer. :rolleyes:
If I save a file using:
If x = vbYes Or i = 0 Then ActiveWorkbook.SaveAs strPath & fname
Then this will leave the file open... When I go to do my next Estimating Sheet it has the one that is open NOT EstimatingSheet?? Here is what I am talking about!

Michael
 
Upvote 0
Ok then!! back to my original question, can I write code to open a file without the directory? Or maybe search for a file then open it?

Michael
 
Upvote 0
Code:
'i find this code useful
cdDir = "C:\Documents and Settings\"

    'Start FileSearch
    With Application.FileSearch
        .LookIn = cdDir
        .Filename = "*" & ".xls"
        .FileType = msoFileTypeExcelWorkbooks
        .SearchSubFolders = True
        .Execute
        If .Execute > 0 Then
        
            'loop through all found files
            For IFoundFiles = 1 To .FoundFiles.Count
                
                'set incidental variables
                Pos = InStrRev(.FoundFiles(IFoundFiles), "\")
                file = Right(.FoundFiles(IFoundFiles), Len(.FoundFiles(IFoundFiles)) - Pos)
                path = Left(.FoundFiles(IFoundFiles), Pos)
                
                                                            Application.DisplayAlerts = False
                Set wbSource = Workbooks.Open(path & file)
                                                            Application.DisplayAlerts = True
                    
                    For isheet = 1 To Worksheets.Count
                        wbSource.Activate
                        sheetName = Sheets(isheet).Name
                        
                        If InStr(sheetName, "MATIN") > 0 Or InStr(sheetName, "mating") > 0 Then  'ESTIMATING


let me know if more explaining is necessary>>


if file="estimating.xls" then 'code to open
the code i mentioned before works well for me as far as checking that the worksheet name matches; the code goes through the directory and subdirectories as well!! which means you can put the directory as C:\
 
Upvote 0
Code:
'i find this code useful
cdDir = "C:\Documents and Settings\"

    'Start FileSearch
    With Application.FileSearch
        .LookIn = cdDir
        .Filename = "*" & ".xls"
        .FileType = msoFileTypeExcelWorkbooks
        .SearchSubFolders = True
        .Execute
        If .Execute > 0 Then
        
            'loop through all found files
            For IFoundFiles = 1 To .FoundFiles.Count
                
                'set incidental variables
                Pos = InStrRev(.FoundFiles(IFoundFiles), "\")
                file = Right(.FoundFiles(IFoundFiles), Len(.FoundFiles(IFoundFiles)) - Pos)
                path = Left(.FoundFiles(IFoundFiles), Pos)
                
                                                            Application.DisplayAlerts = False
                Set wbSource = Workbooks.Open(path & file)
                                                            Application.DisplayAlerts = True
                    
                    For isheet = 1 To Worksheets.Count
                        wbSource.Activate
                        sheetName = Sheets(isheet).Name
                        
                        If InStr(sheetName, "MATIN") > 0 Or InStr(sheetName, "mating") > 0 Then  'ESTIMATING


let me know if more explaining is necessary>>


if file="estimating.xls" then 'code to open
the code i mentioned before works well for me as far as checking that the worksheet name matches; the code goes through the directory and subdirectories as well!! which means you can put the directory as C:\
 
Upvote 0
iknowyou99,
:cool:
Not all sheets start with the "Documents and Settings"
ie: C:\Users\michael\Documents\
So is this what you mean when you say I can change:
which means you can put the directory as C:\
instead of:
cdDir = "C:\Documents and Settings\"
:confused:

thank you,
Michael
 
Upvote 0
Isn't this all I want/need to do?
Code:
Sub FindEstimating
cdDir = "C:\Documents and Settings\" 

    'Start FileSearch 
    With Application.FileSearch 
        .LookIn = cdDir 
        .Filename = "*" & ".xls" 
        .FileType = msoFileTypeExcelWorkbooks 
        .SearchSubFolders = True 
        .Execute 
                               Set wbSource = Workbooks.Open(path & file) 
End Sub

Michael
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,289
Members
449,077
Latest member
Rkmenon

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