|
-
Dec 15th, 2005, 03:27 AM
#1
Thread Starter
Member
[RESOLVED] RESOLVED: Runtime error 1004 when exporting to excel
Hi, my application is getting the followed error
Runtime error 1004: Application defined or Object defined error
and this is the offending piece of code.
myBook.Worksheets(1).Range(bCol).Value = vDate
vDate is a string, and I have checked bCol as well to make sure that they have correct variables.
Any help much appreciated...
Last edited by Santos7772005; Dec 16th, 2005 at 12:48 AM.
Reason: Resolved
-
Dec 15th, 2005, 03:30 AM
#2
Re: Runtime error 1004 when exporting to excel
Post more code than that. It doesn't sound like Excel is being opened correctly.
-
Dec 15th, 2005, 03:43 AM
#3
Re: Runtime error 1004 when exporting to excel
What is the format of the column where that data is going?
-
Dec 15th, 2005, 03:53 AM
#4
Re: Runtime error 1004 when exporting to excel
Post the values of your variables too.
Moved from Classic VB.
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 
-
Dec 15th, 2005, 04:07 AM
#5
Thread Starter
Member
Re: Runtime error 1004 when exporting to excel
Yes, excel is doing something strange, it does not seem to be closing even after my application has quit.
the runtime error problem I fixed by changing vDate to a type String but the problem seems to be with the spreadsheet either not opening or closing properly. If I close out of Vb and then try to open the spreadsheet I get a message that a user (me!) has it open and it can only be opened readonly so its like it has not closed properly.
how I have declared my Excel workbook:
Dim myBook As Excel.Workbook
I open it like this:
fname = exePath & "exportXL.xls"
Set myBook = Workbooks.Open(FileName:=fname)
When I have finished writing the data to the spreadsheet I close it like this:
myBook.Save
myBook.Close
Set myBook = Nothing
Hope this provides a few more clues.
-
Dec 15th, 2005, 04:32 AM
#6
Re: Runtime error 1004 when exporting to excel
Will you try it like this...
VB Code:
Public Sub Test()
Dim exl As Excel.Application
Dim myBook As Excel.Workbook
Dim fName As String
Set exl = New Excel.Application
fName = exePath & "exportXL.xls"
Set myBook = exl.Workbooks.Open(fName)
'stuff
myBook.Save
myBook.Close
Set myBook = Nothing
exl.Quit
Set exl = Nothing
End Sub
-
Dec 15th, 2005, 05:32 AM
#7
Re: Runtime error 1004 when exporting to excel
Using Dee-u's code will work or specifically, this line of code is causing excel to remain open as your using the default Workbooks object without referencing an object variable set to it first.
VB Code:
Set myBook = [b]Workbooks[/b].Open(FileName:=fname)
'Better to do...
Dim oApp As Excel.Application
Set oApp = New Excel.Application
Set myBook = oApp.Workbooks.Open(FileName:=fname)
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 
-
Dec 15th, 2005, 05:58 PM
#8
Thread Starter
Member
Re: Runtime error 1004 when exporting to excel
Hey thanks for the help guys. Appreciate it, seems to have cleared up my problem
-
Dec 15th, 2005, 09:57 PM
#9
Re: Runtime error 1004 when exporting to excel
Glad it worked out.
Ps, as a new member I'll let you know that when you have your thread answered its courteous to mark your thread as Resolved so other members will 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 
-
Dec 16th, 2005, 12:49 AM
#10
Thread Starter
Member
Re: RESOLVED: Runtime error 1004 when exporting to excel
-
Dec 16th, 2005, 12:55 AM
#11
Re: RESOLVED: Runtime error 1004 when exporting to excel
We are glad to be of help.
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
|