QueryTables DataTypes & ColumnWidths Arrays as variables

forumreader

New Member
Joined
Jul 12, 2011
Messages
2
How do I set the datatypes and columnwidths as variables? I get invalid procedure call or argument. Will import different text files and set dt and cw based on names. Thanks for help

Dim dt As Variant
Dim cw As Variant
dt = "2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2"
cw = "7, 7, 5, 2, 7, 16, 3, 15, 11, 9, 9, 9, 7, 3, 3"
With ActiveSheet.QueryTables.Add(Connection:="TEXT;B:\BOMOE\BTR\bfro1.txt", Destination:=Range("A1"))
.Name = "BFRO1"
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(dt)
.TextFileFixedColumnWidths = Array(cw)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Welcome to the Board.

Try:

Code:
dt = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)

and:

Code:
.TextFileColumnDataTypes = dt
 
Upvote 0
Thanks for the quick reply. It worked on both dt and cw. I had tried that before, but not since I changed them to variant instead of string. I get drain bamage sometimes. Now I can finish the macro to import larger than 65536 line, text file import. Works by splitting large text file into subfiles of 65530 lines and import each one with same data types and column widths to separate worksheets. Again thanks.
 
Upvote 0
Welcome to the Board.

Try:

Code:
dt = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)

and:

Code:
.TextFileColumnDataTypes = dt



Hi,

Instead of hardcoding the values, is it possible to dynamically pull the values from excel sheet and pass them to Array. Please help.

Lets say, the Data types are present in sheet "Input" Column 'A' and Column widths in Column 'B'. Please help me in how to pass these values to Array.


Thanks,
Sandeep.
 
Upvote 0
Hi Andrew,

Thanks for the reply.. I tried the code.. but I am getting Invalid call or Argument.. any idea on this?
I am using Excel 2010

HTML:
.TextFileFixedColumnWidths = Application.WorksheetFunction.Transpose(Worksheets("Input").Range("E1:E46").Value)
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,898
Members
452,948
Latest member
Dupuhini

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