Macro to Select file location for lookups

Cat129

Board Regular
Joined
Oct 20, 2012
Messages
96
Morning All,

I'm not sure if this is possible but was hoping you could tell me.

I need to write a macro that does lots of lookups and others things by comparing two spreadsheets. The spreadsheet that is being used as the lookup will have a different file name each time it is run. It is renamed to the date it was last updated and then replaced by the one doing the looking up once all the lookups etc have been completed.

I was thinking of creating some sort of pop up that would ask you to select the file and then the file that you select is used through out the rest of the code.

Is this possible? Or am I over complicating things?

Help!

Thanks,
Cat
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Cat

You mentioned code, could you post it and indicate where you would want to use the selected file in it?
 
Upvote 0
Cat

You mentioned code, could you post it and indicate where you would want to use the selected file in it?

Hey, I cant really. Its 14 modules of code....

I'll try to explain a little more

We have a few hundred text files that generated by our CAD system, and the excel workbook in question loops through them all, delimits them, makes the data usable, renames each sheet, and then saves the workbook as todays date. This workbook is then used by various people and data added to it.

In a few days time an update will be done so the macro will be run again, the issue is each time it is run it starts with a blank workbook.

So we have lookups in place, and other code to compare the data between the two, fill in the gaps and generate data based on the lookups, this is all done manually after the data is generated by the first macro.

What I want to do it make this whole thing into one process.

In my head it would be as simple as

1) Pull all our CAD data into excel and let it do its normal thing
2) Select the file location of the previous version to do lookups
3) Run a macro to do all the lookups and generate data
 
Upvote 0
Will you need to select the file location for all 14 modules?
 
Upvote 0
Hi,

No it would be for the 3rd item in the list. The macros for this haven't been written yet. But I cant hardcore the file name into it as it will have changed each time its ran
 
Upvote 0
Can you post the part of the code where the file location would be required?
 
Upvote 0
It hasn't been created yet. It would be the very first part of the code.

I want a popup that asks the user to select the file.

Then within all the formulas that would need to use it, reference it within the formula
 
Upvote 0
My problem is I dont know how to create the pop up that would allow user to browse to a file, and then return that file location and name into the code
 
Upvote 0
You can use Application.GetOpenFilename to allow the user to browse for and select a file.
Code:
Dim strBasePath As String
Dim strFullPath As String
Dim strFileName As String
Dim strFilePath As String

    strBasePath = "C:\Test\"
    
    ChDir strBasePath
    
    strFullPath = Application.GetOpenFilename("Excel Workbooks (*.xls*),*.xls*", 1, "Choose file", "Select", False)
    
    If strFullPath <> "False" Then
    
        strFileName = Mid(strFullPath, InStrRev(strFullPath, "\") + 1)
        
        strFilePath = Replace(strFullPath, strFileName, "")
        
        MsgBox "File selected:" & vbTab & strFileName, vbExclamation, "Congatulations!"
        
    End If
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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