Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Import text wizard in a macro

I've written a macro to automatically feed the appropriate parameters to the Text Import Wizard to format text data into an active spreadsheet. However, I want the data to be added to the data already in the sheet and the Import Wizards always puts the data in starting at A1. Is there any way to tell it to start putting the data starting at another cell location?
--
Dennis Vlasich
Claremont, CA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Import text wizard in a macro

After playing around, I sort of answered my own question--but it raised another question. Rather than use the File/Open option (per the other suggestions regarding recording macros for the Import Text wizard), I used Data/Import/Import Data option. It builds a slightly different macro than the File/Open, but when I try to add in the code for the GetFileOpen dialog box and feed the "fileToOpen" variable to the Data/Import version of the code in place of a hard-coded path and filename, it gives me an error when running the macro. Any hints of what I'm doing wrong? Here's the code I'm trying to use (by the way, what is the "With, End With all about?):

fileToOpen = Application.GetOpenFileName("Text Files (*.txt), *.txt")
If fileToOpen < False Then
Workbooks.Open Filename:=fileToOpen
End If

With ActiveSheet.QueryTables.Add(Connection:=fileToOpen , _
Destination:=ActiveCell)
.Name = "Pay320"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 3, 9, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, _
2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
--
Dennis Vlasich
Claremont, CA


"Dennis Vlasich" wrote:

I've written a macro to automatically feed the appropriate parameters to the Text Import Wizard to format text data into an active spreadsheet. However, I want the data to be added to the data already in the sheet and the Import Wizards always puts the data in starting at A1. Is there any way to tell it to start putting the data starting at another cell location?
--
Dennis Vlasich
Claremont, CA

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Import text wizard in a macro

You don't want to open the file if you are going to import it. Also, you
removed the "Text:" part of the connection string:

fileToOpen = Application.GetOpenFileName("Text Files (*.txt), *.txt")
If fileToOpen < False Then

With ActiveSheet.QueryTables.Add(Connection:= _
"Text:" & fileToOpen, _
Destination:=ActiveCell)
.Name = "Pay320"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 3, 9, 2, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 2, 2, 2, 2, 2, 2, 2, _
2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With


instead of doing

ActiveCell.Font.bold = True
ActiveCell.Font.ColorIndex = 3
ActiveCell.Interior.colorIndex = 6

you can do

With ActiveCell
.Font.bold = True
.Font.ColorIndex = 3
.Interior.colorIndex = t
End With

--
Regards,
Tom Ogilvy


"Dennis Vlasich" wrote in message
...
After playing around, I sort of answered my own question--but it raised

another question. Rather than use the File/Open option (per the other
suggestions regarding recording macros for the Import Text wizard), I used
Data/Import/Import Data option. It builds a slightly different macro than
the File/Open, but when I try to add in the code for the GetFileOpen dialog
box and feed the "fileToOpen" variable to the Data/Import version of the
code in place of a hard-coded path and filename, it gives me an error when
running the macro. Any hints of what I'm doing wrong? Here's the code I'm
trying to use (by the way, what is the "With, End With all about?):

fileToOpen = Application.GetOpenFileName("Text Files (*.txt), *.txt")
If fileToOpen < False Then
Workbooks.Open Filename:=fileToOpen
End If

With ActiveSheet.QueryTables.Add(Connection:=fileToOpen , _
Destination:=ActiveCell)
.Name = "Pay320"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 3, 9, 2, 1, 1, 1, 1, 1, 1, 1,

1, 1, 1, 2, 2, 2, 2, 2, 2, 2, _
2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
--
Dennis Vlasich
Claremont, CA


"Dennis Vlasich" wrote:

I've written a macro to automatically feed the appropriate parameters to

the Text Import Wizard to format text data into an active spreadsheet.
However, I want the data to be added to the data already in the sheet and
the Import Wizards always puts the data in starting at A1. Is there any
way to tell it to start putting the data starting at another cell location?
--
Dennis Vlasich
Claremont, CA



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import text wizard in a macro

Tom,
Thank you for the help. One minor problem (which I
fixed) is that the separator after "Text:" is a semi-
colon, not a colon, so it should have been "Text;". Once
I made that change it worked exactly as I need it to.
-----Original Message-----
You don't want to open the file if you are going to

import it. Also, you
removed the "Text:" part of the connection string:

fileToOpen = Application.GetOpenFileName("Text Files

(*.txt), *.txt")
If fileToOpen < False Then

With ActiveSheet.QueryTables.Add(Connection:= _
"Text:" & fileToOpen, _
Destination:=ActiveCell)
.Name = "Pay320"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier =

xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 3, 9, 2, 1,

1, 1, 1, 1, 1, 1, 1,
1, 1, 2, 2, 2, 2, 2, 2, 2, _
2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With


instead of doing

ActiveCell.Font.bold = True
ActiveCell.Font.ColorIndex = 3
ActiveCell.Interior.colorIndex = 6

you can do

With ActiveCell
.Font.bold = True
.Font.ColorIndex = 3
.Interior.colorIndex = t
End With

--
Regards,
Tom Ogilvy


"Dennis Vlasich"

wrote in message
news:9B8E9A01-70C5-4111-B10A-

...
After playing around, I sort of answered my own

question--but it raised
another question. Rather than use the File/Open option

(per the other
suggestions regarding recording macros for the Import

Text wizard), I used
Data/Import/Import Data option. It builds a slightly

different macro than
the File/Open, but when I try to add in the code for the

GetFileOpen dialog
box and feed the "fileToOpen" variable to the

Data/Import version of the
code in place of a hard-coded path and filename, it

gives me an error when
running the macro. Any hints of what I'm doing wrong?

Here's the code I'm
trying to use (by the way, what is the "With, End With

all about?):

fileToOpen = Application.GetOpenFileName("Text Files

(*.txt), *.txt")
If fileToOpen < False Then
Workbooks.Open Filename:=fileToOpen
End If

With ActiveSheet.QueryTables.Add

(Connection:=fileToOpen, _
Destination:=ActiveCell)
.Name = "Pay320"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier =

xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 3, 9, 2,

1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 2, 2, 2, 2, 2, 2, 2, _
2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
--
Dennis Vlasich
Claremont, CA


"Dennis Vlasich" wrote:

I've written a macro to automatically feed the

appropriate parameters to
the Text Import Wizard to format text data into an

active spreadsheet.
However, I want the data to be added to the data already

in the sheet and
the Import Wizards always puts the data in starting at

A1. Is there any
way to tell it to start putting the data starting at

another cell location?
--
Dennis Vlasich
Claremont, CA



.

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
Text Import Wizard perplexIN Excel Discussion (Misc queries) 2 March 4th 09 11:45 AM
How to Start Excel in Text Import Wizard for data import rlelvis Setting up and Configuration of Excel 0 July 10th 08 08:40 PM
How do I call up the Text Import Wizard via a macro. Computer, call me if you have a problem Excel Worksheet Functions 4 October 11th 07 10:06 PM
Text Import Wizard GARY Excel Discussion (Misc queries) 1 December 24th 06 08:40 PM
Creating a macro to use the text import wizard abxy[_2_] Excel Programming 3 January 11th 04 12:43 AM


All times are GMT +1. The time now is 03:29 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"