Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make my code edit itself? 1

Status
Not open for further replies.

AcousticalConsultant

Technical User
Sep 20, 2001
45
CA
In my macro, I shell to dos and run a program. But if the program isn't in the proper location, I obviously get an error. I want to be able to prompt the user and allow him to locate the proper location of the file.
Up to here, everything is fine. My problem is when the user enters the new location, I want to go and change the code accordingly, rather than store the new location in a variable and make the user re-enter its location every time he runs the macro!

Here's a portion of my code if it helps...:

FileLoc = "C:\WINDOWS\FILE.EXT"

On Error GoTo ErrHandlr
myval = Shell("command.com /C " & FileLoc, 6)

ErrHandlr:
If (Error = "File not found") Then
MsgBox "Error Starting Application:" & vbCr & vbCr _
& "Application Location: " & FileLoc & vbCr _
& "Description: " & Err.Description,_
vbCritical, "Error"
Exit Sub
End If


Now rather than use the ErrHandlr, I'd branch to a form where the user can browse (using Common Dialog Box) and find the newly located file.

Thanks in advance!

Pascal

 
Dont try and amend code on the fly. Store the location of the file in an INI file, table or Registry key, whichever is most appropriate. Try the stored location and if it fails, prompt the user for a new location then update the stored value.

M.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top