![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
|
I have a macro that I use that copies part of the active worksheet, opens an existing workbook, pastes the stuff copied. The newly opened workbook then does some calculations based upon what is pasted. Then it copies the results back into the original workbook.
Problem is the workbook that I open from the macro sometimes changes names or location. How do I create an input messagebox that promts the user to choose the location of the file? Thanks! |
|
|
|
|
|
#2 |
|
.
Join Date: Feb 2002
Location: Akron, Ohio USA
Posts: 789
|
Something like this:
Code:
On Error Goto NotFound
NewFN = Worksheets("Sheet1").Range("Z1").value
Workbooks.Open Filename:=NewFN
On Error GoTo 0
' The rest of your code
....
Exit Sub
NotFound:
Msg = "OtherFile.xls not found in expected directory. Click OK to browse for this file, or click Cancel"
ans = MsgBox(prompt:=Msg, Buttons:=vbOKCancel + vbDefaultButton1 + vbInformation, Title:="File not found")
If ans = vbOK Then
NewFN = Application.GetOpenFilename(fileFilter:="Excel Files (*.xls), *.xls", Title:="Browse for OtherFile.xls")
If NewFN = False Then
' They clicked Cancel
Exit Sub
End If
Workbooks.Open Filename:=NewFN
Worksheets("Sheet1").Range("Z1").value = NewFn
Resume Next
End If
Exit Sub
Bill
__________________
Preview my latest book for Free |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
|
WOW! A reply from MrExcel!!! Am honored that my question was worthy enough (or stupid enough).
Thanks!! [ This Message was edited by: Cosmos75 on 2002-04-10 12:05 ] |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|