473,385 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

VB code in Excel macro

Don
Within an application that I am writing, I am trying to allow the user to select a text (.txt) file from the Open File dialog box in Excel. This is working.
The problem is, I want to eliminate the user from having to go through the 3-step Text Import Wizard, which appears right after user selects the (.txt) file from the Open File dialog box. I want to suppress this Wizard from appearing and do that work behind the scenes in the programming.

Code to display the Open File dialog box that works:

With Application
.DefaultFilePath = ("*.*") 'Show all file types in Open File dialog box
.Dialogs(xlDialogOpen).Show 'Show open dialog box to select text file
.DefaultFilePath = strMyFilePath 'Reset original default file path
End With

Code to suppress Wizard and do delimiting by Tab behind the scenes which doesn’t work:

strFileName = ActiveWorkbook.Name
Application.DisplayAlerts = False
Workbooks.OpenText FileName:= _
strFileName, Origin _
:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, Tab:=True
Application.DisplayAlerts = True

The second group of code works but the Wizard opens first and you have to go through the step process in the Wizard before the second group of code is executed.

Can you help?

Jul 21 '05 #1
2 5314
Here is how I open all of the files in a folder, and
bypass the wizard.
Dim MyFile As String, Mydir As String
Mydir = CurDir()
MyFile = Dir("*.txt")
Do While MyFile <> ""
Workbooks.OpenText Filename:= _
Mydir & "\" & MyFile _
, Origin:=xlWindows, StartRow:=1,
DataType:=xlDelimited, TextQualifier _
:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, Semicolon:= _
False, Comma:=False, Space:=False, Other:=True,
OtherChar:="|", _
FieldInfo:=Array(Array(1, 1), Array(2, 1), Array
(3, 1), Array(4, 1))

MyFile = Dir()
Loop
Hope that helps,

LeRoy

-----Original Message-----
Within an application that I am writing, I am trying to allow the user to select a text (.txt) file from the
Open File dialog box in Excel. This is working. The problem is, I want to eliminate the user from having to go through the 3-step Text Import Wizard, which
appears right after user selects the (.txt) file from the
Open File dialog box. I want to suppress this Wizard from
appearing and do that work behind the scenes in the
programming.
Code to display the Open File dialog box that works:

With Application
.DefaultFilePath = ("*.*") 'Show all file types in Open
File dialog box .Dialogs(xlDialogOpen).Show 'Show open dialog box to select text file .DefaultFilePath = strMyFilePath 'Reset original default file path End With

Code to suppress Wizard and do delimiting by Tab behind the scenes which doesnâ?Tt work:
strFileName = ActiveWorkbook.Name
Application.DisplayAlerts = False
Workbooks.OpenText FileName:= _
strFileName, Origin _
:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _ xlDoubleQuote, Tab:=True
Application.DisplayAlerts = True

The second group of code works but the Wizard opens first and you have to go through the step process in the
Wizard before the second group of code is executed.
Can you help?

.

Jul 21 '05 #2
Don
Thanks for the suggestion, I will try it.

----- an*******@discussions.microsoft.com wrote: -----

Here is how I open all of the files in a folder, and
bypass the wizard.
Dim MyFile As String, Mydir As String
Mydir = CurDir()
MyFile = Dir("*.txt")
Do While MyFile <> ""
Workbooks.OpenText Filename:= _
Mydir & "\" & MyFile _
, Origin:=xlWindows, StartRow:=1,
DataType:=xlDelimited, TextQualifier _
:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, Semicolon:= _
False, Comma:=False, Space:=False, Other:=True,
OtherChar:="|", _
FieldInfo:=Array(Array(1, 1), Array(2, 1), Array
(3, 1), Array(4, 1))

MyFile = Dir()
Loop
Hope that helps,

LeRoy

-----Original Message-----
Within an application that I am writing, I am trying to allow the user to select a text (.txt) file from the
Open File dialog box in Excel. This is working. The problem is, I want to eliminate the user from having to go through the 3-step Text Import Wizard, which
appears right after user selects the (.txt) file from the
Open File dialog box. I want to suppress this Wizard from
appearing and do that work behind the scenes in the
programming.
Code to display the Open File dialog box that works:
With Application

.DefaultFilePath =

("*.*") 'Show all file types in Open
File dialog box .Dialogs(xlDialogOpen).Show 'Show open dialog box to select text file .DefaultFilePath = strMyFilePath 'Reset original default file path End With
Code to suppress Wizard and do delimiting by Tab behind the scenes which doesnâ?Tt work: strFileName = ActiveWorkbook.Name Application.DisplayAlerts = False
Workbooks.OpenText FileName:= _
strFileName, Origin _
:=xlWindows, StartRow:=1, DataType:=xlDelimited,

TextQualifier:= _ xlDoubleQuote, Tab:=True
Application.DisplayAlerts = True
The second group of code works but the Wizard opens first and you have to go through the step process in the
Wizard before the second group of code is executed. Can you help?
.

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sylvia | last post by:
Dear All, Would appreciate if someone can help me out on this. I have an Excel Add-in which is only available on the web server. The Add-in allows user to retrieve data from a proprietary...
2
by: Mrs Howl | last post by:
I don't know if there's even a way to do what I want. I click on a button in an Access form, and it opens an instance of Excel, and opens a workbook and runs a macro that's in it. So far, fine,...
0
by: Alex | last post by:
i have a module in Access which opens an existing Excel file and envokes a macro within the Excel file to draw graphs. now i am trying to convert the Excel macro to an Access one so that the...
3
by: John | last post by:
Is there a way to code the button that's available in the query window--microsoft excel icon that exports to excel. I know transferspreadsheet will do this---but I want the query, which is in a...
6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
3
by: etwebbox | last post by:
Hoping someone has some ideas on how to solve this issue: I have a macro in excel which runs a query against an Access DB (it actually calls a query inside of Access). The query is not bringing...
8
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a...
4
by: Rich Wallace | last post by:
Is there a way to open an Excel file and either respond to or supress the Macro warning window via VB.NET? Dim oExcel As Excel.Workbook Dim sFilePath As String = "C:\DailyReport.xls" oExcel...
2
by: cr113 | last post by:
I just upgraded from Office 2000 to Office 2003. My VB.NET Excel macro calls don't work any longer. Here is how I make my Excel macro call from VB.NET: Dim objExcel as Excel.Application ...
4
by: shara | last post by:
Hello, I have a php script that outputs an excel sheet.The user has to download macro every time he wants to run the macro on the excel sheet. Is there anything in php where the code downloads...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.