If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Macro rewrite - Import Text File

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-16-06, 09:03
Rex Deckard Rex Deckard is offline
Registered User
 
Join Date: Mar 2004
Posts: 31
Macro rewrite - Import Text File

We received a file from a consultant that they need us to refresh daily. It contains a macro that allows the file to update based on some source data that is stored in a TEXT file.

The macro code is as follows

Sheets("AP_AR").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

When it is run, Excel opens an Import Text File Prompt, which we then need to point at the directory where AP_AR.txt exists.

Rather then have to do this, isn't there a much easier way to code this so that when it is run the VBA already has the path and just uses those paths to update. There are a total of 10 sheets in the Macro, so to have it automated would be very helpful.

Thank you in advance.
Reply With Quote
  #2 (permalink)  
Old 06-16-06, 12:44
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 533
ADO Import works very well for this. You will need to create a reference to the "MS Active X 2.x" Dll in Tools References. You will also need to write code to run Text to Columns after importing the text. This requires custom Excel VB to run.

Here are some examples. You can find more by searching for 'Excel ADO Text Import' in any flavor search engine.

http://www.exceltip.com/st/Import_da...Excel/430.html

Importing more than 65,536 rows into Excel
http://www.danielklann.com/excel/imp...files_into.htm

(the second link didn't work when I just tried it. I've used this before so it may just be temporary)
__________________
~

Bill
Reply With Quote
  #3 (permalink)  
Old 06-16-06, 15:02
Rex Deckard Rex Deckard is offline
Registered User
 
Join Date: Mar 2004
Posts: 31
Thanks, I will take a crack with that.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On