Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help using FileDialog with OpenText

I am trying to import a text file into a specific worksheet. Since the name
and location of the file changes every month, I am trying to use the
FileDialog method. After the user has selected the file, I would like to use
OpenText method to import the file. In the file, Columns 1 through 11 need
to be specified as type TEXT and Column 12 can be general. I am having a
having a hard time trying to understand the correct way writing the syntax
for the FieldInfo in the OpenText.

Any suggestions would be helpful.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help using FileDialog with OpenText

I think using the application.getopenfilename would be more straight forward.
And if you record a macro when you import a typical text file, you'll see the
code to specify the fieldinfo parm.

Text files can vary--they can be delimited or fixed width. So any guess that
matched your requirements would be pretty amazing.

But in general, your recorded code after the tweaking would look like:

Option Explicit
Sub Testme01()

Dim myFileName As Variant
Dim DestCell as Range
Dim TextWks as worksheet

myFileName = Application.GetOpenFilename(filefilter:="Text Files, *.Txt", _
Title:="Pick a File")

If myFileName = False Then
MsgBox "Ok, try later" 'user hit cancel
Exit Sub
End If

Set DestCell = worksheets("sheet1").range("a1")

Workbooks.OpenText Filename:=myFileName '....rest of recorded code here!

set TextWks = activesheet

'this'll wipe out any existing stuff on the destcell's worksheet
textwks.cells.copy _
destination:=destcell

textwks.parent.close savechanges:=false

End Sub



Fredriksson wrote:

I am trying to import a text file into a specific worksheet. Since the name
and location of the file changes every month, I am trying to use the
FileDialog method. After the user has selected the file, I would like to use
OpenText method to import the file. In the file, Columns 1 through 11 need
to be specified as type TEXT and Column 12 can be general. I am having a
having a hard time trying to understand the correct way writing the syntax
for the FieldInfo in the OpenText.

Any suggestions would be helpful.


--

Dave Peterson
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
FileDialog AMDRIT Excel Programming 1 October 21st 05 10:17 PM
FileDialog - Not available in 2k? RWN Excel Programming 3 March 12th 05 05:25 AM
FileDialog Help Maynard Excel Programming 0 August 4th 04 01:43 PM
FileDialog Jag Man Excel Programming 3 February 2nd 04 04:50 AM
After OpenText all pastes from external apps use format from OpenText Jim[_31_] Excel Programming 1 November 8th 03 02:17 AM


All times are GMT +1. The time now is 06:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"