![]() |
Opening a file with User Input
I am saving files based on a number and in the macro I need the user
to input the number for the file they wish to open and have the rest of the macro continue. Right now I am using an InputBox to have the user input the information but I dont know how to use the variable that saves the users information and have it apart of the Open Filename command. This does not work because that command needs to have text and it wont let me put a variable in there. Any suggestions? |
Opening a file with User Input
Perhaps...
Sub a() Dim FileNum As Integer On Error Resume Next FileNum = InputBox("Enter file number") If Err.Number = 0 Then Workbooks.Open "File" & FileNum If Err.Number = 0 Then ''file opened ok Else MsgBox "Could not open file" End If Else MsgBox "Invalid file number" End If End Sub -- Jim wrote in message oups.com... |I am saving files based on a number and in the macro I need the user | to input the number for the file they wish to open and have the rest | of the macro continue. Right now I am using an InputBox to have the | user input the information but I dont know how to use the variable | that saves the users information and have it apart of the Open | Filename command. This does not work because that command needs to | have text and it wont let me put a variable in there. Any suggestions? | |
Opening a file with User Input
On Mar 27, 2:23 pm, "Jim Rech" wrote:
Perhaps... Sub a() Dim FileNum As Integer On Error Resume Next FileNum = InputBox("Enter file number") If Err.Number = 0 Then Workbooks.Open "File" & FileNum If Err.Number = 0 Then ''file opened ok Else MsgBox "Could not open file" End If Else MsgBox "Invalid file number" End If End Sub -- wrote in message oups.com... |I am saving files based on a number and in the macro I need the user | to input the number for the file they wish to open and have the rest | of the macro continue. Right now I am using an InputBox to have the | user input the information but I dont know how to use the variable | that saves the users information and have it apart of the Open | Filename command. This does not work because that command needs to | have text and it wont let me put a variable in there. Any suggestions? | This works great, do you know if there is a way to set a directory so the program knows where to look for the file the user will specify. Thank you. |
Opening a file with User Input
take one step in between. Define a string that contains the filename. Based
on the feedback from the inputbox add the number to the string - the result is again a string. Thus MyFilename = MyFilename & inputbox thereafter use the open command " wrote: I am saving files based on a number and in the macro I need the user to input the number for the file they wish to open and have the rest of the macro continue. Right now I am using an InputBox to have the user input the information but I dont know how to use the variable that saves the users information and have it apart of the Open Filename command. This does not work because that command needs to have text and it wont let me put a variable in there. Any suggestions? |
All times are GMT +1. The time now is 10:04 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com