Sunday, August 2, 2009

Is there a way to automatically update a file name in Visual Basic on Excel?

BAsically, I have a VB programme that I want to use in a file, but users of the file change the name when they use it. I want VB to automatically change the filename in the code when the name of the file is changed. Is this possible?

Is there a way to automatically update a file name in Visual Basic on Excel?
If you wrote some code to get them to input the name of the file first then you could easily change it to write the file using the code and keep the new file name. Something like this:








filename = InputBox("what would you like to rename the file as")





Set myFSO = CreateObject("Scripting.FileSystemObject...


Set WriteStuff = myFSO.OpenTextFile("c:\" %26amp; filename, 8, True)


WriteStuff.WriteLine(whatever the new data is put the variable here)


WriteStuff.Close


SET WriteStuff = NOTHING


SET myFSO = NOTHING


No comments:

Post a Comment