ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Variable Macro (https://www.excelbanter.com/excel-discussion-misc-queries/102682-variable-macro.html)

Heather O'Malley

Variable Macro
 
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

Dave O

Variable Macro
 
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


Dave O

Variable Macro
 
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



All times are GMT +1. The time now is 09:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com