LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Which Excel event to call when opening a .txt file

Subject: Which Excel event to call when opening a .txt file
I am opening a materialcodeconflictid.txt file in Excel. When I open
this .txt file, Excel opens a “Text Import Wizard” where I can specify
format of various columns etc. I want to automate opening of Text and
setting various formats. So I have developed a macro by recording all
of these actions, matcodeconflict_leadzero , shown below. This macro
however has hardcoded file name so I want to make it more flexible. I
can modify this macro to take file name as a parameter.
Sub matcodeconflict_leadzero()
Workbooks.OpenText Filename:="C:\TEMP\matcodeconflictid.txt",
Origin:= _
xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:=
_
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False,
Semicolon:=False _
, Comma:=True, Space:=False, Other:=False,
FieldInfo:=Array(Array(1, 1), _
Array(2, 2), Array(3, 1), Array(4, 1), Array(5, 1), Array(6,
1), Array(7, 1), Array(8, 1), _
Array(9, 2), Array(10, 1), Array(11, 1), Array(12, 1),
Array(13, 1), Array(14, 1)), _
TrailingMinusNumbers:=True
Application.Left = 68.5
Application.Top = 43
End Sub
To this end, I created application events. I have setup an application
procedure x1APP_WorkbookOpen and inside this procedure I print name of
the workbook just for debugging.
Public WithEvents xlApp As Excel.Application
Private Sub Workbook_Open()
Set xlApp = Application
End Sub
Private Sub Workbook_Close()
Set xlApp = Nothing
End Sub
Private Sub xlApp_WorkbookOpen(ByVal Wb As Workbook)

MsgBox "Welcome..." & Wb.Name
‘ call matcodeconflict_leadzero (Wb.Name)
End Sub

I was hoping that inside this application procedure after printing
name of workbook, I can call my macro
matcodeconflict_leadzero
Problem I am finding is that “Text Import Wizard” is shown before
x1APP_WorkbookOpen is called.
What I want to do is not to open “Text Import Wizard” at all instead
call a macro which will do this formatting for me. How can I do this?
What application event I have to set so all of above can be done
automatically.




 
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
Macro for Opening Reuters, Opening Excel File, Closing Excel File Tsp245 Excel Programming 2 August 14th 08 07:24 PM
Call Event as Sub Clayman Excel Programming 2 August 7th 07 03:40 PM
Opening Excel workbook via automation doesn't fire event procedures? Jeremy Gollehon[_3_] Excel Programming 2 July 7th 06 04:50 PM
how can i call macro in powerpoint file from excel file pm[_2_] Excel Programming 3 January 6th 06 10:40 PM
How to run a Sub while opening the xls file (what event to use)? ira Excel Programming 1 December 26th 03 03:55 PM


All times are GMT +1. The time now is 05:26 PM.

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

About Us

"It's about Microsoft Excel"