I have a file that is being created weekly. There is a spreadsheet that contains data I want for another excel file. I want to copy the entire worksheet and past it into another file. However the date in the file name changes weekly. Is there a way to create a prompt in the VBA to browse for the file and permit the user to select the file needing to be imported.
Thanks!
![]()
Last edited by ggremel; 03-07-2011 at 02:21 PM.
Try this
Option Explicit Sub openfile() Dim sFil As String Dim sTitle As String Dim sWb As String Dim iFilterIndex As Integer on error goto err_handler ' Set up list of file filters sFil = "Excel Files (*.xls),*.xls" ' Display *.xls by default iFilterIndex = 1 ' Set the dialog box caption sTitle = "Select File to Zip" ' Get the filename sWb = Application.GetOpenFilename(sFil, iFilterIndex, sTitle) Workbooks.Open Filename:=sWb Exit Sub err_handler: Msgbox "No selection made" End Sub
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
You are a virtual rock star. Thank you.
If you are satisfied with the solution(s) provided, please mark your thread as Solved.
How to mark a thread Solved
Go to the first post
Click edit
Click Go Advanced
Just below the word Title you will see a dropdown with the word No prefix.
Change to Solved
Click Save
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Will do. If I want to past the file name in a cell (Filename:=sWb). How would I go about adding this to the report.xls file.
Thanks
If the code is in the Report workbook then
ThisWorkBook.Sheet1.Cells(1,1).Value=sWb
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
If the code is in the Report workbook then
ThisWorkBook.Sheet1.Cells(1,1).Value=sWb
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
You can't place the line of code that I gave you into a cell.
I've reviewed your code & made some improvements.
Option Explicit Sub openfile() Dim sFil As String Dim sTitle As String Dim sWb As String Dim iFilterIndex As Integer With Application .ScreenUpdating = False ' Set up list of file filters sFil = "Excel Files (*.xls),*.xls" ' Display *.xls by default iFilterIndex = 1 ' Set the dialog box caption sTitle = "Select File to Open" ' Get the filename On Error GoTo err_handler sWb = Application.GetOpenFilename(sFil, iFilterIndex, sTitle) Workbooks.Open Filename:=sWb ActiveWorkbook.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("BRT Data").Range("A1") ThisWorkbook.Sheets("Sheet1").Cells(1, 1) = "Data source: " & sWb 'close source workbook ActiveWorkbook.Close False exit_proc: .ScreenUpdating = True .CutCopyMode = False End With Exit Sub err_handler: MsgBox "No selection made", vbCritical, "User Cancelled" Resume exit_proc End Sub
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks