|
-
Apr 23rd, 2004, 09:26 AM
#1
Thread Starter
Junior Member
[RESOLVED] error on oXL.Workbooks.Open
I've made a form in VB6 and compiled an exe file. Clicking on the .exe file opens the form, clicking on the button starts excel and opens a .xls file.
The code is:
Code:
Option Explicit
Private Sub Command1_Click()
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim MyPath, MyName, MyFile As String
' Start Excel and get Application object.
Set oXL = CreateObject("Excel.Application")
oXL.Visible = True
' Get file
MyName = "\MySubFolder\MyXls.xls"
MyPath = App.Path
MyFile = MyPath & MyName
oXL.Workbooks.Open MyFile
oXL.Application.Visible = True
Exit Sub
Err_Handler:
MsgBox Err.Description, vbCritical, "Error: " & Err.Number
End Sub
I get an error when excel is trying to open the .xls file (i'm sorry i can't describe the exact error, but i think it was something like a critical error in Myfile.exe caused .... in module <unknown> at....).
the error occurs when the script is excecuting oxl.workbooks.open
This happened on two different machines running on windows98 and office2000.
It works fine on my PC running on windows XP and office 2002 and on my pc at work running on windows2000 and office 2002.
I've tried different codes for the line oxl.workbooks.open like:
oXL.Workbooks.Open (FileName:=MyFile)
oXL.Workbooks.Open ("C:\MySubFolder\MyXls.xls")
set oWB = oXL.Workbooks.Open(FileName:=MyFile)
set oWB = oXL.Workbooks.Open ("C:\MySubFolder\MyXls.xls")
None worked 
Please help!
Thanks in advance!
Cheers,
Arie
Last edited by arie ribbens; May 12th, 2004 at 08:29 AM.
-
Apr 23rd, 2004, 09:59 AM
#2
Hyperactive Member
Hi,
I think the problem lies in this line:
Dim MyPath, MyName, MyFile As String
In VB you declare it as:
Dim MyPath As String, MyName As String, MyFile As String
The way you have it, only MyFile is defined.
CyberJar
-
Apr 24th, 2004, 04:15 PM
#3
If that was the issue then why does it work on some systems
and not others. Wouldn't it fail al the time?
What about oXL.Workbooks.Open ("C:\MySubFolder\MyXls.xls")
no use of MyFile at all and arie ribbens said that failed also.
What about the reference to Excel in VB. The version of Excel that
was compiled with was Excel 2002. i know that the .Open method
is present in 2000 but could be work looking at. Try late binding
for your Excel object vars.
Also was the program installed (setup package) on the other
systems or just copied over? Could be a versioning issue???
I think we need a little more info to solve the issue?
HTH
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 
-
Apr 26th, 2004, 04:43 AM
#4
Thread Starter
Junior Member
thank you for replying.
I will post a screendump with the error message on it so you have some more detailed information.
@RobDog888: thanks for really reading my problem and your reply.
i'm still pretty new to vb so i don't really understand what you mean with:
Try late binding for your Excel object vars.
do you mean something like:
Dim oXL as Object
Dim oWB as Object
?
the program is very tiny atm. Just to code posted here. Its just one form with one button to test the code. I compiled the project to a .exe file and copied it with the subfolder including the .xls file to a floppy . Took the floppy to the win98 machine with office 2000 and run it which results in the error.
This is the easiest way to change code and test quickly.
I used to make a setup package and install on the win98 machine but that took too much time and the error message is the same.
I'll keep you updated!
Cheers,
Arie
-
Apr 26th, 2004, 11:07 AM
#5
Yes, that is late binding.
Can you try compiling the code on a system with vb and office 2000?
HTH
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 
-
Apr 27th, 2004, 02:19 AM
#6
Thread Starter
Junior Member
i tried the late binding, but still the same error.
I'll try to compile on the win98/office2000 machine this evening as that machine is at home.
Here's a picture with the error-message, hope this will make it clearer for you:

Cheers,
Arie
-
Apr 27th, 2004, 11:37 AM
#7
Ok, here is what I did. The modified code below is the working
version, I think. Your code was crashing on our 2000 Terminal
server with the same sub folders/file, etc. So I did the late
binding and changed the oXL.Application.Visible = True to
oXL.Visible = True and set the objects to nothing after we are
through with them. Also, I took out the reference to Excel in the
project.
I compiled it, copied it to our 2000 Terminal server and I got the
workbook to open. I cant test on 98, but if there were issues on
2000 Terminal server then perhaps they are fixed for 98 as well.
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim oXL As Object
Dim oWB As Object
Dim MyPath As String
Dim MyName As String
Dim MyFile As String
' Start Excel and get Application object.
Set oXL = CreateObject("Excel.Application")
oXL.Visible = True
' Get file
MyName = "\MySubFolder\MyXls.xls"
MyPath = App.Path
MyFile = MyPath & MyName
oXL.Workbooks.Open MyFile
oXL.Visible = True
Set oWB = Nothing
Set oXL = Nothing
Exit Sub
Err_Handler:
MsgBox Err.Description, vbCritical, "Error: " & Err.Number
End Sub
HTH
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 
-
Apr 28th, 2004, 02:16 AM
#8
Thread Starter
Junior Member
thank you sooo much RobDog888!!
I'll give it a try when i get home from work. I'll let you know if it worked.
Cheers,
Arie
-
Apr 29th, 2004, 02:38 AM
#9
Thread Starter
Junior Member
-
Apr 29th, 2004, 12:41 PM
#10
Quick question, you state that the systems have Office installed,
but do they have Excel installed? Runable?
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 
-
May 2nd, 2004, 07:44 AM
#11
Thread Starter
Junior Member
-
May 12th, 2004, 08:28 AM
#12
Thread Starter
Junior Member
found out there was something wrong with one of the two win98/office2000 systems i was testing on. The following code worked fine on XP/officeXP, win98/office2000 and win95/office97 machines.
Thanks to everyone who helped out:
Code:
Option Explicit
Private Function Str_BuildPath(LeftPath As String, _
RightPath As String)
Dim strLeft As String
Dim strRight As String
If Right$(LeftPath, 1) = "\" Then
strLeft = LeftPath
Else
strLeft = LeftPath & "\"
End If
If Left$(RightPath, 1) = "\" Then
strRight = Right(RightPath, Len(RightPath) - 1)
Else
strRight = RightPath
End If
Str_BuildPath = strLeft & strRight
End Function
Private Sub Command1_Click()
Dim oXL As Object
Dim oWB As Object
Dim MyName As String
Dim MyFile As String
On Error Goto Catch
' Start Excel and get Application object.
Set oXL = CreateObject("Excel.Application")
oXL.Visible = True
' Get file
MyName = "\MySubFolder\MyXls.xls"
MyFile = Str_BuildPath(App.Path, MyName)
' (See pvt. routine, above.)
oXL.Workbooks.Open MyFile
MsgBox "User: Please Click Ok to make Excel Close."
Exit Sub
GoTo Finally
Catch:
Dim Err_Num As Long
Dim Err_Desc As String
Err_Num = Err.Number
Err_Desc = Err.Description
Resume Finally
Finally:
On Error Resume Next
Call oWB.Close(SaveChanges:=False) '<-- ** or True **
Call oXL.Quit
Set oWB = Nothing
Set oXL = Nothing
' Report Error if we had one:
If Err_Num <> 0 Then
On Error GoTo 0
Call Err.Raise(Err_Num, "Command1_Click", Err_Desc)
End If
End Sub
Cheers,
Arie
-
May 12th, 2004, 10:46 AM
#13
Glad to hear you figured it out, but "win95/office97". Didn't know
95 was still alive.
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 
-
May 18th, 2004, 08:44 AM
#14
Thread Starter
Junior Member
Glad to hear you figured it out, but "win95/office97". Didn't know 95 was still alive.
Thought so too, but i guess some people still have old crappy systems and only win95 can run on it
Well i wasn't testing my program for win95, but it's good to know it works on really old systems as well.
I'm going to add some more functionality soon, so maybe i'll have to post here again (hope not).
Cheers,
Arie
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
|