Variable Macro

  • Thread starter Heather O'Malley
  • Start date
H

Heather O'Malley

I am trying to create a macro with a file name variable. The code I have
written doesn't seem to work, any ideas!

Dim ImportDir As String
Dim ImportFile As String

ImportDir = Range("a17").Value
ImportFile = Range("b17").Value

Windows("ImportFile").Activate
Sheets("Top 10 month").Select
 
D

Dave O

Hi, Heather-
Instead of this line:
Windows("ImportFile").Activate

....try this:
Windows(ImportFile & ".xls").Activate

Did you post the entire macro? What are you trying to do? There may
be additional code involved if you're trying to specify a location and
filename to open.

Dave O
 
D

Dave O

Oops- just realized: if the value in B17 already includes the .xls
along with the filename, then try removing the quotes. It may be just
changing
Windows("ImportFile").Activate
to this:
Windows(ImportFile).Activate
 
Top