Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 08-10-2009, 03:14 AM   #1 (permalink)
zedman3d's Avatar
 
I am of the highest lvl..

Join Date: Oct 2007

Location: Sydney, Australia

Posts: 2,452

zedman3d will become famous soon enoughzedman3d will become famous soon enough

Default Write to excel, VBA/VB6

Code:
Private Sub cmdCheck1_Click()

'Add a reference to MS Excel xx.0 Object Library
Dim oApp As Excel.Application
Dim oWB As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
'Create an Excel instalce.
Set oApp = New Excel.Application
'Open the desired workbook
Set oWB = oApp.Workbooks.Open(FileName:="G:\Book1.xls")
'Open specifc sheet
Set oXLSheet = oWB.Worksheets(1)
'Do any modifications to the workbook.
'...
oXLSheet.Cells(2, 1).Value = "hello"
'Save the xls file
oWB.SaveAs FileName:="G:\Book1_MOD.xls"
'close and clean up resources
oWB.Close SaveChanges:=False
Set oWB = Nothing
oApp.Quit
Set oApp = Nothing
End Sub
What have i done wrong? Nothing happens at all.
Thank you.
__________________



My pick up line is: I know Vernong.

Trotter: "Ask all the questions you want... whatever we don't know, we'll make
up something that sounds pretty good."

Antec-User: "I have a display now, but the darn system is crash-bandicoot on stock"
zedman3d is offline  
Old 08-10-2009, 05:10 AM   #2 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,159

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: Write to excel, VBA/VB6

Do you not get any errors either? Do you mean that G:\Book1_MOD.xls is empty or do you mean that it does not exist?
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is offline  
Old 08-11-2009, 12:37 PM   #3 (permalink)
 
Newb Techie

Join Date: Aug 2009

Posts: 1

filipk is on a distinguished road

Default Re: Write to excel, VBA/VB6

Hi,

i belive this is your problem:
Set oXLSheet = oWB.Worksheets(1)

you selected (1) sheet which is 2nd sheet in your workbook. Try to see if text you expected to be written in your Excel file is on 2nd sheet. If that is the problem, to write on first sheet use oWB.Worksheets(0). This is custom mistake when working with arrays, lists, etc.

If you want to improve your appliaction I advice you to use GemBox Excel component for .NET instead of Excel Automation for many reasons. Here you can see few of them why it's better to avoid Excel Automation.

Filip
filipk is offline  
Old 08-12-2009, 02:11 AM   #4 (permalink)
zedman3d's Avatar
 
I am of the highest lvl..

Join Date: Oct 2007

Location: Sydney, Australia

Posts: 2,452

zedman3d will become famous soon enoughzedman3d will become famous soon enough

Default Re: Write to excel, VBA/VB6

Nope, none of the above.
Turns out i needed to include a reference to 12.0 Excel.

Thanks though.
PS: Its just for school so im not fussed about needing liscenses and such.
__________________



My pick up line is: I know Vernong.

Trotter: "Ask all the questions you want... whatever we don't know, we'll make
up something that sounds pretty good."

Antec-User: "I have a display now, but the darn system is crash-bandicoot on stock"
zedman3d is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
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
How To Open Microsoft Excel Spreadsheets Without Excel Osiris Tips, Tricks & Tutorials 0 06-21-2009 12:52 PM
CSS Menu objecterror Web Graphics, Design, Digital Images 9 02-06-2009 12:16 PM
microsoft excel 2003 thaingsokheng Windows Operating Systems and Software 12 09-25-2008 10:46 PM
DVD Data Burning enigm@tic Hardware Troubleshooting 4 08-25-2008 08:30 PM
Excel 2007 bug superdave1984 Windows Operating Systems and Software 0 09-26-2007 11:48 AM