User Input File Name

K

kem

I want to be able to call a workbook (to copy data from)
based on the file name that the user inputs. The workbook
to be called would be already open (but there would likely
be other workbooks also open at the same time).

I tried something like this:

Dim RawDataSheet As String
RawDataSheet = InputBox("What is the name of the file
that contains the raw data?")
Windows("RawDataSheet").Activate
Range("A1").Select

Thanks in advance
 
R

Ray at

You put your variable name in quotes. That won't work, unless you have a
window with a caption of RawDataSheet. Try:

Dim RawDataSheet As String
RawDataSheet = InputBox("What is the name of the file
that contains the raw data?")
Windows(RawDataSheet).Activate
Range("A1").Select


You may want to do something like "If Left(RawDataSheet, 4) <> ".xls" Then
RawDataSheet = RawDataSheet & ".xls" or put in some sort of error handling
at least.

Ray at work
 
G

Gord Dibben

kem

One method(among others).

Dim RawDataSheet As String
RawDataSheet = InputBox("What is the name of the file_
that contains the raw data?")
Application.Workbooks(RawDataSheet & ".xls").Activate
Range("A1").Select
End Sub

Gord Dibben Excel MVP - XL97 SR2 & XL2002
 

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

Top