Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Change filename & auto_open
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Change filename & auto_open
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 cottage6 wrote: 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. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Change filename & auto_open
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"? "JW" wrote: 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 cottage6 wrote: 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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Change Filename in Macro | Excel Discussion (Misc queries) | |||
Change hardcoded filename | Excel Programming | |||
script to change filename | Excel Programming | |||
Recorded macro: What happens if I change filename? | Excel Discussion (Misc queries) | |||
Change Filename | Excel Programming |