What is to be done when the location of our raw data has moved and there is a relating Excel file to maintain? Manually, we can go to
1) click connection, 2) click properties, 3) click definition, 4) click browse, 5) locate the file, 6) set up delimited Text Import Wizard Step 1, click next, 7) set up delimiters Step 2, 8) set up step 3, 9) click OK again
[It probably will work. However there might also be an error from MS Office Excel after all these hard work. And if it works, we need to do it 7 times when there are 7 worksheets to be updated.]
Quicker way:
Place the cursor on a cell within the cell range of the query
Open VBEditor (Alt-F11)
Open the Intermediate window (Ctrl-G)
Type the command: ?ActiveCell.QueryTable.Connection [press enter]
Open VBEditor (Alt-F11)
Open the Intermediate window (Ctrl-G)
Type the command: ?ActiveCell.QueryTable.Connection [press enter]
(The relevant connection info will be echoed back, e.g. TEXT;G:\raw_data\file1.txt
(Notice that the drive G: is changed to D: in this case)
Optional (as required):
Once the above is done, the delimiters will all be automatically set to none. So to set the delimiter as a comma:
Once the above is done, the delimiters will all be automatically set to none. So to set the delimiter as a comma:
Type the command: ActiveCell.QueryTable.TextFileCommaDelimiter = true [press enter]
(To set the delimiter as a comma... )
(To set the delimiter as a comma... )
(Or any delimiter as needed e.g. ;)
