Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old October 23rd, 2003, 08:17 AM
vb_user vb_user is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 6 vb_user User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
OLE control using excel

hello,
I am not able to enter value cell by cell in excelsheet by using OLE Control.
I have included OLE in the form. From "Inser Object" dialog box I have selected "Microsoft Excel Worksheet". Now I have created one command to execute the process. In the commnd event I have included the following code.

OLE1.object.Cells(1, 1).Value = "Sep"
OLE1.object.Cells(2, 1).Value = 3
OLE1.object.Cells(3, 1).Value = 4
OLE1.object.Cells(4, 1).Value = 6

But this is not working. Its give me error as "object doesn't support this property or method". Can any one tell me what should be the solution of this problem ?
Please provide me some sample examples or links of OLE control by using excel in visual basic.

Thnaks,
vb_user.

Reply With Quote
  #2  
Old October 23rd, 2003, 09:49 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Now,I guess u have a mistake in your code:U wouldn't use ole object,Should use office object(contains excel object).
Plz vist the msdn to get more kownledge.http://msdn.microsoft.com/library/d...objectmodel.asp

http://msdn.microsoft.com/library/d...xcelobjects.asp

http://www.microsoft.com/officedev/...es/OffObjPr.htm

Last edited by cleverpig : October 23rd, 2003 at 09:54 AM.

Reply With Quote
  #3  
Old March 31st, 2008, 10:55 AM
mimi_fara mimi_fara is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 86 mimi_fara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 10 h 4 m 10 sec
Reputation Power: 5
OLE objects on Access form

Quote:
Originally Posted by cleverpig
Now,I guess u have a mistake in your code:U wouldn't use ole object,Should use office object(contains excel object).
Plz vist the msdn to get more kownledge.http://msdn.microsoft.com/library/d...objectmodel.asp

http://msdn.microsoft.com/library/d...xcelobjects.asp

http://www.microsoft.com/officedev/...es/OffObjPr.htm


I'm trying to achive the same goal , but the links are not valid anymore, could someone pelase help me ?

Thanks

Reply With Quote
  #4  
Old March 31st, 2008, 02:32 PM
Frank20 Frank20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 248 Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 9 h 24 m 7 sec
Reputation Power: 10
Code:
Sub Test01()
 Dim appXL As Object

 On Error GoTo ErrorHandler
 Set appXL = GetObject(, "Excel.Application")
 
 ChDir "C:\Documents and Settings\Administrator\Desktop"
 appXL.ActiveWorkbook.Sheets("Sheet1").Range("A1").Value = "[test]"
 appXL.ActiveWorkbook.Save
 appXL.ActiveWorkbook.Close
 appXL.Quit
 
 Set appXL = Nothing
 Exit Sub

ErrorHandler:
 If Err = 429 Then
  MsgBox Err
  Set appXL = CreateObject("Excel.Application")
  appXL.Workbooks.Add
 End If

'Resume execution at same line that caused the error:
 Resume Next
End Sub

Reply With Quote
  #5  
Old April 1st, 2008, 06:18 AM
mimi_fara mimi_fara is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 86 mimi_fara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 10 h 4 m 10 sec
Reputation Power: 5
Thank you for your code,
Is there a way to just have the data on the excel sheet that is added on the access form <OLE object> without saving it anywhere?

Reply With Quote
  #6  
Old April 1st, 2008, 03:31 PM
Frank20 Frank20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 248 Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 9 h 24 m 7 sec
Reputation Power: 10
Quote:
Originally Posted by mimi_fara
Thank you for your code,
Is there a way to just have the data on the excel sheet that is added on the access form <OLE object> without saving it anywhere?


Please explain what you're trying to do.
1. Is there an environment that you're working inside (here)? Is it Access?
2. From here, is there a place (there) that you're trying to insert data to or extract data from? Is it Excel?
3. The external place (there): Do you want to retrieve data from it, or push data to it? What kind of data is it?

Reply With Quote
  #7  
Old April 2nd, 2008, 06:21 AM
mimi_fara mimi_fara is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 86 mimi_fara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 10 h 4 m 10 sec
Reputation Power: 5
Thank you for your interest in helping me frank !
i have an access form that i placed an excel unbound object (the excel object is not linked to any excel document.

im trying to create a process for the user that runs on the access database with a click on a button, the data will be gathered and displayed on the excel sheet, and then some graphs will be generated, the data wont be saved, its just on the fly and the report will then be printed right away, but no data will be saved.

i tried the code you provided me, but it opens the MS excel application, and i cant do anything esle while its working, because it takes the focus..

i would like the process to run without having excel application open to the user.

thank you
Mimi

Reply With Quote
  #8  
Old April 2nd, 2008, 02:32 PM
Frank20 Frank20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 248 Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 9 h 24 m 7 sec
Reputation Power: 10
So you do want to have a Workbook open. Already open? (Whenever your Access routine is run?)

GetObject() gets the object of a pre-opened Excel instance. Excel must already be running.

CreateObject() makes a new Excel instance. It will load a new Excel app. into the screen.

So, do you want to manually keep track of whether Excel is already onscreen? Do you want it to load automatically if it's not already there? Do you want to keep only one Excel instance in memory (with 1 or more Workbooks inside) at any given time?


Quote:
...the data will be gathered and displayed on the excel sheet, and then some graphs will be generated, the data wont be saved, its just on the fly and the report will then be printed right away...
But won't that also prevent you from doing other things while that's happening? I don't understand your stated objection that way.

Last edited by Frank20 : April 2nd, 2008 at 09:25 PM.

Reply With Quote
  #9  
Old April 3rd, 2008, 01:18 AM
zynder's Avatar
zynder zynder is offline
Not much of a contributor
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: Hidden
Posts: 800 zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 22 h 6 m 32 sec
Reputation Power: 647
Send a message via Yahoo to zynder
What is your output in Access? Do you think it's possible to store it in memory. Hold the data in the memory, run an instance of Excel then put it on excel. Im just shooting in the dark here. Might give us more info.

-zyn

Reply With Quote
  #10  
Old April 3rd, 2008, 04:14 AM
mimi_fara mimi_fara is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 86 mimi_fara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 10 h 4 m 10 sec
Reputation Power: 5
Quote:
Originally Posted by Frank20
So you do want to have a Workbook open. Already open? (Whenever your Access routine is run?)

GetObject() gets the object of a pre-opened Excel instance. Excel must already be running.

CreateObject() makes a new Excel instance. It will load a new Excel app. into the screen.

So, do you want to manually keep track of whether Excel is already onscreen? Do you want it to load automatically if it's not already there? Do you want to keep only one Excel instance in memory (with 1 or more Workbooks inside) at any given time?


But won't that also prevent you from doing other things while that's happening? I don't understand your stated objection that way.


Do i have to open an instance of the excel object to have my data visibel one the unbound object frame of excel object? I do not want to have excel application open, or if it has to be open, i dont want it to be visible for the user or having the focus. and i would want everything to run (data ) and show (graphs) on the unbound object frame of excel object.

Reply With Quote
  #11  
Old April 3rd, 2008, 04:18 AM
mimi_fara mimi_fara is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 86 mimi_fara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 10 h 4 m 10 sec
Reputation Power: 5
unbound OLE object, please help ?

Quote:
Originally Posted by zynder
What is your output in Access? Do you think it's possible to store it in memory. Hold the data in the memory, run an instance of Excel then put it on excel. Im just shooting in the dark here. Might give us more info.

-zyn


i wouldn't want to use the memory of the pc as i have lots of process running on the same time, and it would make the pc run out of memory as the data handled is big.

i work in finance, and i'm trying to generate a report to the user that shows the securities we hold within portfolios and their prices and performance calculations and then on another tab of the unbound frame of excel object, show differnet graphs of performance etc, that would be generated from the data that has been listed on the first tab of the excel sheet.
The generated results will then be printed as a report, but will not be saved anywhere.
the user would like to have everything on the Database, thats why i cant use exterior excel sheets, or save them anywhere

Last edited by mimi_fara : April 4th, 2008 at 08:58 AM.

Reply With Quote
  #12  
Old April 5th, 2008, 01:48 AM
zynder's Avatar
zynder zynder is offline
Not much of a contributor
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: Hidden
Posts: 800 zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1Folding Points: 141777 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 22 h 6 m 32 sec
Reputation Power: 647
Send a message via Yahoo to zynder
This is getting complicated with the use of Access and Excel. If you have experience with VBA then you can do it with VB6. Make an app with database then export in excel what you need.

Reply With Quote
  #13  
Old April 8th, 2008, 08:15 AM
mimi_fara mimi_fara is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 86 mimi_fara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 10 h 4 m 10 sec
Reputation Power: 5
Hello again !
i have worked on with your code, but i have an issue. i have used the following code :
Code:
  
   Dim appXL As Object
   Set appXL = GetObject(, "Excel.Application")
   Me.excelsheet.Verb = acOLEVerbShow 
   Me.excelsheet.Action = acOLEActivate
   
   appXL.ActiveWorkbook.Sheets("sheet1").Range("C1") = nav


now, excelsheet is the unbound object frame on my access form. when i use the above code, the excel application opens and the user get to see what is happening when i assign the variable to the range.

but, as i dont want the application to be visible to the user i set the me.excelsheet.verb= acOLEVerbHide

and when i use this and try to assign the value to the Range C1 i get the error " Run-time error 91: Object variable or with block variable not set"

how could i get around this ?

Thanks !!





Quote:
Originally Posted by Frank20
Code:
Sub Test01()
 Dim appXL As Object

 On Error GoTo ErrorHandler
 Set appXL = GetObject(, "Excel.Application")
 
 ChDir "C:\Documents and Settings\Administrator\Desktop"
 appXL.ActiveWorkbook.Sheets("Sheet1").Range("A1").Value = "[test]"
 appXL.ActiveWorkbook.Save
 appXL.ActiveWorkbook.Close
 appXL.Quit
 
 Set appXL = Nothing
 Exit Sub

ErrorHandler:
 If Err = 429 Then
  MsgBox Err
  Set appXL = CreateObject("Excel.Application")
  appXL.Workbooks.Add
 End If

'Resume execution at same line that caused the error:
 Resume Next
End Sub

Reply With Quote
  #14  
Old April 10th, 2008, 12:11 PM
Frank20 Frank20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 248 Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level)Frank20 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 9 h 24 m 7 sec
Reputation Power: 10
If this is some kind of object physically embedded on the Access Form, can you just grab the corners of it in design mode and make it very, very small?

Reply With Quote