Opening a file with User Input

  • Thread starter Thread starter dswiders
  • Start date Start date
D

dswiders

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?
 
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
|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?
|
 
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

--

|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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top