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

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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