Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Filename in Macro Havenstar Excel Discussion (Misc queries) 3 January 16th 09 05:27 PM
Change hardcoded filename CLR Excel Programming 6 August 29th 06 05:21 PM
script to change filename jeramie[_2_] Excel Programming 2 February 11th 06 09:36 PM
Recorded macro: What happens if I change filename? [email protected] Excel Discussion (Misc queries) 2 January 26th 05 11:54 PM
Change Filename Planner Excel Programming 3 August 11th 04 03:43 PM


All times are GMT +1. The time now is 03:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"