Home |
Search |
Today's Posts |
#1
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
|
|||
|
|||
How to create Excel workbook from VB6?
Hi,
What do I need to add to VB6 project to be able to create Excel'97 document on the fly? How do I get access to the same objects that are available from Excel itself via VBA? Is there a good source with examples for such stuff? Thank you. |
#2
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
|
|||
|
|||
How to create Excel workbook from VB6?
Hi Kurt,
If you create an Excel instance, then you have access to all of the objects. so as an example Dim xlApp As Object Dim xlWB As Object Dim xlWS As Object Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True ' or not as required Set xlWB = xlApp.Workbooks.Add Set xlWS = xlWB.Worksheets.Add 'etc. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Kurt Remlin" wrote in message m... Hi, What do I need to add to VB6 project to be able to create Excel'97 document on the fly? How do I get access to the same objects that are available from Excel itself via VBA? Is there a good source with examples for such stuff? Thank you. |
#3
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
|
|||
|
|||
How to create Excel workbook from VB6?
"Bob Phillips" wrote in message
... Hi Kurt, If you create an Excel instance, then you have access to all of the objects. so as an example Dim xlApp As Object Dim xlWB As Object Dim xlWS As Object Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True ' or not as required Set xlWB = xlApp.Workbooks.Add Set xlWS = xlWB.Worksheets.Add 'etc. A better way (because it's early-bound): Set a reference to the Excel Library (Menu: Project/References, scroll to Microsoft Excel xx.x Object Library) Dim xlApp As Excel.Application Dim xlWkBk As Excel.Workbook Dim xlWkSht As Excel.Worksheet Set xlApp = New Excel.Application xlApp.Visible = True 'as needed. Set xlWkBk = xlApp.Workbooks.Add Set xlWkSht = xlWkBk.Worksheets(0) There will always be at least one worksheet in a new workbook, so you don't need to add one unless you need more than one worksheet. The number of sheets in the new workbook will depend on the user's setting, and can range from 1 to 255 in Excel 2003. The only problem is if the user has an earlier version of Excel and you use a method or property that has been introduced since, your app will crash on their machine. Austin |
#4
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
|
|||
|
|||
How to create Excel workbook from VB6?
"AustinMN" wrote in message ... "Bob Phillips" wrote in message ... Hi Kurt, If you create an Excel instance, then you have access to all of the objects. so as an example Dim xlApp As Object Dim xlWB As Object Dim xlWS As Object Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True ' or not as required Set xlWB = xlApp.Workbooks.Add Set xlWS = xlWB.Worksheets.Add 'etc. A better way (because it's early-bound): It's horses for courses. Better in some instances, not so in others. It is not black and white. The only problem is if the user has an earlier version of Excel and you use a method or property that has been introduced since, your app will crash on their machine. And a later version may lose the reference (hence late bound) |
#5
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
|
|||
|
|||
How to create Excel workbook from VB6?
"Bob Phillips" wrote in message
... "AustinMN" wrote in message ... "Bob Phillips" wrote in message ... Hi Kurt, If you create an Excel instance, then you have access to all of the objects. so as an example Dim xlApp As Object Dim xlWB As Object Dim xlWS As Object Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True ' or not as required Set xlWB = xlApp.Workbooks.Add Set xlWS = xlWB.Worksheets.Add 'etc. A better way (because it's early-bound): It's horses for courses. Better in some instances, not so in others. It is not black and white. The only problem is if the user has an earlier version of Excel and you use a method or property that has been introduced since, your app will crash on their machine. And a later version may lose the reference (hence late bound) While that's possible (Micro$oft can break anything), I've never experienced it. I've written over 100,000 lines of VBA specifically for Excel for 7 clients dating back to 1994. Not one line has broken because a method or property has disappeared. MS Outlook, on the other hand... =8-(( Austin |
#6
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
|
|||
|
|||
How to create Excel workbook from VB6?
"AustinMN" wrote in message ... "Bob Phillips" wrote in message ... "AustinMN" wrote in message ... "Bob Phillips" wrote in message ... Hi Kurt, If you create an Excel instance, then you have access to all of the objects. so as an example Dim xlApp As Object Dim xlWB As Object Dim xlWS As Object Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True ' or not as required Set xlWB = xlApp.Workbooks.Add Set xlWS = xlWB.Worksheets.Add 'etc. A better way (because it's early-bound): It's horses for courses. Better in some instances, not so in others. It is not black and white. The only problem is if the user has an earlier version of Excel and you use a method or property that has been introduced since, your app will crash on their machine. And a later version may lose the reference (hence late bound) While that's possible (Micro$oft can break anything), I've never experienced it. I've written over 100,000 lines of VBA specifically for Excel for 7 clients dating back to 1994. Not one line has broken because a method or property has disappeared. That's not what I said. I mentioned lost references. And if you think that doesn't happen, just hang out here a while and you will see many examples. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how do you create a task from an excel 2007 workbook? | Excel Discussion (Misc queries) | |||
How to create & delete sheets in a shared Excel workbook? | Excel Worksheet Functions | |||
Create a new excel workbook from access | Excel Discussion (Misc queries) | |||
how to create a chart in excel with data from another workbook | Charts and Charting in Excel | |||
Create invoices from excel workbook | Excel Worksheet Functions |