|
-
Aug 1st, 2006, 03:05 PM
#1
Thread Starter
Junior Member
[RESOLVED] problem with Workbooks Open event
I have the following code :
VB Code:
Function Vals(File As String, Prob As Integer) As Variant
Set oXLApp = New Excel.Application
oXLApp.Visible = True
oXLApp.Workbooks.OpenText FileName:=File, _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, _
Comma:=False, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1)), _
TrailingMinusNumbers:=True
Set oXLBook = oXLApp.Workbooks(File)
Set oXLSheet = oXLBook.Worksheets(1)
.....
Vals = ...
End Function
I get a subscript out of range error at the
Set oXLBook = oXLApp.Workbooks(File)
statement - why ?
I've checked that File does contain the correct string.
If I change the statement to :
Set oXLBook = oXLApp.Workbooks.Open(File)
everything works fine, but now I don't parse the text file correctly (It seems like it assumes default settings that are different from those that I specify in the OpenText statement).
Thanks,
-
Aug 1st, 2006, 08:39 PM
#2
Re: problem with Workbooks Open event
try
VB Code:
set oxlbook = oXLApp.Workbooks.OpenText (FileName:=File, _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, _
Comma:=False, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1)), _
TrailingMinusNumbers:=True)
pete
-
Aug 2nd, 2006, 01:10 AM
#3
Re: problem with Workbooks Open event
Set oXLBook = oXLApp.Workbooks(File)
File is the full path and filename of the workbook but for a workbooks collection name all you need is the filename or just provide the index number.
VB Code:
Set oXLBook = oXLApp.Workbooks(1)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 2nd, 2006, 09:35 AM
#4
Thread Starter
Junior Member
Re: problem with Workbooks Open event
westconn1 :
when I try that code I get 'expected function or variable at the OpenText statement. I don't understand why.
RobDog888 :
the code compiles but the Excel file is still not parsed right (default settings that are different from those that I specify in the OpenText statement).
-
Aug 2nd, 2006, 09:43 AM
#5
Thread Starter
Junior Member
Re: problem with Workbooks Open event
I was mistaken - the code :
Set oXLBook = oXLApp.Workbooks(1)
works (parses) as per the OpenText statement.
Thanks for the help !
-
Aug 2nd, 2006, 11:48 AM
#6
Re: problem with Workbooks Open event
No prob.
Dont forget to Resolve your thread so other members know its solved.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|