Change filename & auto_open

G

Guest

I have an Auto_Open macro that imports a .csv file; the macro calls the
Import_CSV sub. I need to create a "start again" macro button a user can
click that does exactly what Auto_Open does, however, the import filename
changes, so I need to call the Import CSV_Raw sub. Filename is the only
change in this whole mess of code. There must be some way to avoid repeating
all the code in another macro that calls Import CSV_Raw, I'm just not smart
enough to figure it out. That's where you all come in! Any help would be
much appreciated.
 
J

JW

Couple different ways:
Declare a Public variable such as:
Public csvFileName as String
Before you call the Import_CSV sub, place something like
csvFileName = "C:\whatever.csv"
In your Import_CSV sub, replace any hardcoded filename with the
variable name csvFileName

or, the way I would recommend
Create one sub called Import_CSV with an arguement.
Sub Import_CSV(ByVal csvFileName As String)
Replace any reference to hardcoded filenames within the sub with
csvFileName.
Then you can call the sub whenever needed and just supply the filename
in the call.
Call Import_CSV("C:\whatever.csv")
or
Call Import_CSV("C:\something_else.csv")

HTH
 
G

Guest

JW,
Thanks for the reply. I tried the second recommended option, but got an
error "not able to find the text file". Maybe it has to do with the "refresh
background query"?
 

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