PC Review


Reply
Thread Tools Rate Thread

Change filename & auto_open

 
 
=?Utf-8?B?Y290dGFnZTY=?=
Guest
Posts: n/a
 
      21st Sep 2007
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 With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      21st Sep 2007
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 With Quote
 
=?Utf-8?B?Y290dGFnZTY=?=
Guest
Posts: n/a
 
      25th Sep 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Filename in Macro Havenstar Microsoft Excel Misc 3 16th Jan 2009 05:27 PM
change filename rob Microsoft Excel Programming 2 21st Dec 2008 07:31 PM
Re: Change filename Dmitry Streblechenko Microsoft Outlook VBA Programming 10 29th Mar 2007 09:24 PM
excel97-change filename jaypee Microsoft Excel Discussion 1 23rd Jan 2006 02:36 PM
Change Filename Planner Microsoft Excel Programming 3 11th Aug 2004 03:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:29 PM.