Problem using Data Import and VBA

JazzSP8

Well-known Member
Joined
Sep 30, 2005
Messages
1,227
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Hi All

I am working on a workbook that will automatically import data from system reports (tab delimited), add up a column, dump the figure in a predefined cell and move onto the next report.

I got it working with one set of data and thought I was laughing, how wrong I was, I tried it with a new set of data and my cells were all given a value of Zero.

On investigation I discovered that if I recorded a macro to import the new data there was a subtle difference.

Originally when I recorded the file I got this;

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\" & Environ("Username") & "\Desktop\Report\ACE", _
Destination:=Sheets("Import").Range("A1"))
.Name = "ACE"

But I tried again this morning and got this;

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\Desktop\Report\ACE", Destination:= _
Sheets("Import").Range("A1"))
.Name = "ACE_54"

The ".Name" has changed.

I can guess this is because Excel has stored this number somewhere as either a count or a tempoary file?

Is there something I can change to make it work every time I want to run the macro?

As always, thanks in advance for any help that can be given... :)
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi

That doesn't appear to be the only thing that has changed - You have it pointing at a directory with name Environ("Username") in the original?

Anyway, check Insert>Names>Define - this is where the query settings are held (ie in a workbook name). One gets generated each time you use the Add method of the QueryTable object. I don't *think* that the zero values is down to this - are you sure the source data is in the same structure?
 
Upvote 0
Hi Richard

Sorry, yes - I added the Environ("Username") part of the path so then it could work on other peoples computers.

I checked out the Insert > Names > Define and you were right, the names are all listed in there, I am just going to delete them all now (there are 20 queries with 53 of each - D'oh!) to see if that solves the problem.

The data is in the same format, that was one of the first things I checked.

I shall post back and let you know how I get on :)
 
Upvote 0
Hi again Richard

Just to let you know that I deleted all the old queries and am back up and running again now.

Thanks for your help .. Again .. :)
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top