Import Text Files with VBA- How to set TextFilePlatform to a code page

kienleong

New Member
Joined
Mar 17, 2010
Messages
13
Hello

I am writing a macro that changes the filepath for an existing text file import as a QueryTable. I want to set the connection parameters to variables and reapply them with a different filepath.

Code:
Dim DataType() as Variant
Dim Platform as Integer
Dim TableCell As Range
Dim TabDelimiter as Boolean, CommaDelimiter as Boolean

Set TableCell = Wksht.Range("A10")           
ReDim DataType(1 To UBound(TableCell.QueryTable.TextFileColumnDataTypes))
            
DataType = TableCell.QueryTable.TextFileColumnDataTypes
TabDelimiter = TableCell.QueryTable.TextFileTabDelimiter
CommaDelimiter = TableCell.QueryTable.TextFileCommaDelimiter
Platform = TableCell.QueryTable.TextFilePlatform

With Wksht.Range("A10").QueryTable
    .Connection = ConnectPath
    .TextFileColumnDataTypes = DataType
    .TextFilePlatform = Platform
    .TextFileParseType = xlDelimited
    .TextFileTabDelimiter = TabDelimiter
    .TextFileCommaDelimiter = CommaDelimiter
End With

This works fine for all parameters except TextFilePlatform. I want to set it to the code page (eg. 437 for IBM-PC, 65000 for Unicode)

VBA help says that

XlPlatform can be one of these XlPlatform constants.
xlMacintosh
xlMSDOS
xlWindows

and .QueryTable.TextFilePlatform has a number that refers to one of these constants.

However, the macro recorder assigns a code page number to the TextFilePlatform property.

How do I assign a variable to original code page and not have it reset to the default Windows (ANSI)?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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