|
-
Sep 14th, 2001, 11:04 AM
#1
Thread Starter
Lively Member
Text box info from vb to Excel
Ok this is my problem, I have a program that calculates costs and displays the costs in 3 text boxes. I need to be able for VB to open a new excel sheet and put the info from the text boxes in to the cells.
This is the code I have:
Dim x1app As Excel.Application
Dim x1book As Excel.Workbook
Dim x1sheet As Excel.Worksheet
Set x1app = New Excel.Application
Set x1book = x1app.Workbooks.Add
Set x1sheet = x1book.Worksheets.Add
x1sheet.Cells(1, 1).Value = Text1.Text
x1sheet.Cells(2, 1).Value = Text2.Text
x1sheet.Cells(3, 1).Formula = "r1c1 +r2c1"
Text3.Text = x1sheet.Cells(3, 1)
But when I run it I get an error saying: Invalid use of new key word and the line
Set x1app = New Excel.Application is highlighted.
Please can some one help
-
Sep 14th, 2001, 11:52 AM
#2
Lively Member
Excel
Try this:
Set x1app = CreateObject("Excel.application")
in place of this:
Set x1app = New Excel.Application
-
Sep 14th, 2001, 11:57 AM
#3
Thread Starter
Lively Member
it worked!!!!!
Thanks mate I really appreciate it.
-
Sep 28th, 2001, 07:19 AM
#4
Hyperactive Member
Any ideas
I have used the code in this thread and it seems to work, the only problem I have is that I can't find the excel sheet, called Book1, it has opened. If I try again it opens another excel sheet, Book2, which also can't find.
It is only when I shut down my computer, it asks me do I want to save the changes in Book1 and Book2.
Any ideas to where they are and how I can find them.
kia kaha kia maia - give of your best, be confident in your own ability
-
Sep 28th, 2001, 11:10 AM
#5
Conquistador
Couldn't test it sorry, (Still yet to install Office after a clean format), but this should solve your problems:
VB Code:
Dim x1app As Excel.Application
Dim x1book As Excel.Workbook
Dim x1sheet As Excel.Worksheet
Set x1app = CreateObject("Excel.application")
Set x1book = x1app.Workbooks.Add
Set x1sheet = x1book.Worksheets.Add
x1app.Visible = True
x1sheet.Cells(1, 1).Value = Text1.Text
x1sheet.Cells(2, 1).Value = Text2.Text
x1sheet.Cells(3, 1).Formula = "r1c1 +r2c1"
Text3.Text = x1sheet.Cells(3, 1)
-
Sep 28th, 2001, 12:26 PM
#6
Hyperactive Member
kia kaha kia maia - give of your best, be confident in your own ability
-
Sep 28th, 2001, 11:41 PM
#7
Hyperactive Member
How do I
Thanks for the help above.
How do I go about calling a particular .xls file, ie say I have a Test.xls and I want to bring that up.
What coding would need to be put in the above coding for that to work
Thanks guys
kia kaha kia maia - give of your best, be confident in your own ability
-
Sep 28th, 2001, 11:55 PM
#8
Fanatic Member
VB Code:
Dim objExcel As Excel.Application
On Error Resume Next
Set objExcel = GetObject(",Excel.Application")
If Err.Number <> 0 Then
Set objExcel = CreateObject("Excel.Application")
End If
Err.Clear
On Error GoTo 0
objExcel.Visible = True
objExcel.WindowState = xlNormal
objExcel.Workbooks.Open FileName:="C:\Book5.xls"
-
Sep 29th, 2001, 09:29 AM
#9
Hyperactive Member
Text for Textbox, what for Combobox?
Hi Guys and Gals
I know that I can use .text for a text box to take through to Excel. What can I use to take the text thats in a Combobox through to Excel?
Below is what I am using
objExcel.Cells(23, 9).Value = txtLast10.Text
objExcel.Cells(5, 10).Value = cboDept1.????
Thanks once again
kia kaha kia maia - give of your best, be confident in your own ability
-
Sep 29th, 2001, 10:28 AM
#10
Fanatic Member
objExcel.Cells(5, 10).Value = CboDept1.List(0) will give you the 1st item in the combobox.(the list in combos start at zero)
If you want the 10th item, objExcel.Cells(5, 10).Value = CboDept1.List(9)
-
Sep 29th, 2001, 10:36 AM
#11
Hyperactive Member
Thanks, but what if
Thanks for that coding
But what if the user has decided to use say one the items in the combox. Say he also has 10 items in the combox. I will not know which one he has selected, so I want to have the one he has selected to go through to Excel. Does that make sense? I hope so.
Thanks
kia kaha kia maia - give of your best, be confident in your own ability
-
Sep 29th, 2001, 09:04 PM
#12
Conquistador
objExcel.Cells(5, 10).Value = CboDept1.List(CboDept1.ListIndex)
.ListIndex gets the index of the currently selected file
Cheers
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
|