PC Review


Reply
Thread Tools Rate Thread

How do I import a .dat file into excel using VB scripting?

 
 
seth@blueksoft.com
Guest
Posts: n/a
 
      1st Mar 2007
I have a program that writes tab seperated values into a .dat file. If
I were to open this .dat file in excel using the import wizard, the
formatting is perfect because I already I have rows/columns set up
within the .dat file.

Basically, my goal is to have a VB script that runs at the end of my
program which will read from the .dat file and import that data into
excel, so I can use the math functions built-in to excel. Also, so
someone else could then use the program and overwrite that .dat file
with their own data to export to their own spreadsheet.


*creating objects
'Dim excelApp As Object'
'Dim ExcelSheet As Object'

*error handling
'On Error Resume Next'

*start up excel
'Set excelApp = CreateObject("Excel.Application")'
'excelApp.Application.Visible=True'


** open an xls (fileVariable contains the directory and a blank excel
document to use, I am not sure I need this or if there is a way to
create a 'fresh' xls to write the dat file to)

'Set ExcelSheet = excelApp.Workbooks.Open(FileName:=fileVariable,
ReadOnly:=False)'

~~~~~
Thats all I have so far. What I need to be able to do is basically
open the .dat file and put the data into that opened Excel file and
KEEP EXCEL OPEN so I can use the spreadsheet for Math. If I execute
what I currently have I see excel open (the blank document i think)
and close immediately.
Can anyone help out this newbie to VB?

 
Reply With Quote
 
 
 
 
Greg Glynn
Guest
Posts: n/a
 
      1st Mar 2007
You need to do comething like this:

MyFilename = Application.GetOpenFilename(filefilter:="Text files,
*.dat", MultiSelect:=False)

If MyFilename <> "" And MyFilename <> "False" Then
Workbooks.OpenText Filename:=MyFilename, Origin:=xlWindows,
StartRow:=1, _
DataType:=xlDelimited, TextQualifier:=xlNone,
ConsecutiveDelimiter:=False, _
Tab:=True, Semicolon:=False, Comma:=False, _
Space:=False, Other:=False, FieldInfo:=Array(1, 1)
End if

 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      1st Mar 2007
Try adding this line:

Set ExcelSheet = excelApp.Workbooks.Open(FileName:=fileVariable,
ReadOnly:=False)'

excelApp.UserControl = True

--
Regards,
Tom Ogilvy


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a program that writes tab seperated values into a .dat file. If
> I were to open this .dat file in excel using the import wizard, the
> formatting is perfect because I already I have rows/columns set up
> within the .dat file.
>
> Basically, my goal is to have a VB script that runs at the end of my
> program which will read from the .dat file and import that data into
> excel, so I can use the math functions built-in to excel. Also, so
> someone else could then use the program and overwrite that .dat file
> with their own data to export to their own spreadsheet.
>
>
> *creating objects
> 'Dim excelApp As Object'
> 'Dim ExcelSheet As Object'
>
> *error handling
> 'On Error Resume Next'
>
> *start up excel
> 'Set excelApp = CreateObject("Excel.Application")'
> 'excelApp.Application.Visible=True'
>
>
> ** open an xls (fileVariable contains the directory and a blank excel
> document to use, I am not sure I need this or if there is a way to
> create a 'fresh' xls to write the dat file to)
>
> 'Set ExcelSheet = excelApp.Workbooks.Open(FileName:=fileVariable,
> ReadOnly:=False)'
>
> ~~~~~
> Thats all I have so far. What I need to be able to do is basically
> open the .dat file and put the data into that opened Excel file and
> KEEP EXCEL OPEN so I can use the spreadsheet for Math. If I execute
> what I currently have I see excel open (the blank document i think)
> and close immediately.
> Can anyone help out this newbie to VB?
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import Excel File into Access DB where user can specify file name andcell range to import ssa Microsoft Access External Data 1 18th May 2011 01:18 AM
Scripting the import of a PST file warlockvix@gmail.com Microsoft Outlook 1 20th Aug 2007 11:29 PM
Re: Scripting Import of Excel Data into Access Ken Snell \(MVP\) Microsoft Access 0 9th Dec 2006 05:22 PM
Software of scripting to grab data from MS word file and fill in Excel fields? Joe Blo Microsoft Excel Discussion 3 6th Oct 2004 09:54 PM
Software of scripting to grab data from MS word file and fill in Excel fields? Joe Blo Microsoft Excel Programming 2 6th Oct 2004 09:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:10 PM.