Open file dialog and apply formating

Anarki

New Member
Joined
Oct 9, 2006
Messages
5
Hi Guys,

I have a current macro that opens a txt file and uses the import text wizard to format the data

it currently looks like this

Code:
Workbooks.OpenText Filename:= _
        "C:\Documents and Settings\Anarki\Desktop\hw on b1\bbbbbb.txt", Origin:=437, _
       StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(20 _
        , 9), Array(23, 1), Array(27, 9), Array(28, 1), Array(32, 9), Array(35, 1), Array(39, 9), _
        Array(40, 1), Array(44, 9), Array(47, 1), Array(51, 9), Array(52, 1), Array(56, 9), Array( _
        59, 1), Array(63, 9), Array(64, 1), Array(68, 9), Array(71, 1), Array(75, 9), Array(76, 1), _
        Array(80, 9), Array(83, 1), Array(87, 9), Array(88, 1), Array(92, 9), Array(95, 1), Array( _
        99, 9), Array(100, 1), Array(104, 9)), TrailingMinusNumbers:=True


However as you can see i have set a constant file name and path, i would like to be able to have an open dialog and select the text file i need but still apply the same formating with the import text wizard

i can get the open dialog

Code:
With Application.Dialogs(xlDialogOpen)
   .Show
End With

but i am unsure how to still apply the same formating


any ideas?

Thanks!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Anarki

New Member
Joined
Oct 9, 2006
Messages
5
Just a bit of an update I was able to do it after much trial and error

The correct code to do my task was
Code:
Dim vFilename As Variant
vFilename = Application.GetOpenFilename("Text Files,*.txt")
Workbooks.OpenText Filename:= _
        vFilename, Origin:=437, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(20 _
        , 9), Array(23, 1), Array(27, 9), Array(28, 1), Array(32, 9), Array(35, 1), Array(39, 9), _
        Array(40, 1), Array(44, 9), Array(47, 1), Array(51, 9), Array(52, 1), Array(56, 9), Array( _
        59, 1), Array(63, 9), Array(64, 1), Array(68, 9), Array(71, 1), Array(75, 9), Array(76, 1), _
        Array(80, 9), Array(83, 1), Array(87, 9), Array(88, 1), Array(92, 9), Array(95, 1), Array( _
        99, 9), Array(100, 1), Array(104, 9)), TrailingMinusNumbers:=True

Setting the filename as a variant and refering it to the getopenfilename did the trick
 

Forum statistics

Threads
1,136,592
Messages
5,676,690
Members
419,644
Latest member
KeelsM

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
Top