Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default 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   Report Post  
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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 do you create a task from an excel 2007 workbook? VMeyer Excel Discussion (Misc queries) 0 December 22nd 08 08:40 PM
How to create & delete sheets in a shared Excel workbook? Gemma @ Sweeney Excel Worksheet Functions 0 May 21st 08 03:42 AM
Create a new excel workbook from access ST Excel Discussion (Misc queries) 1 July 31st 06 04:15 PM
how to create a chart in excel with data from another workbook Charlene Charts and Charting in Excel 2 October 7th 05 04:56 AM
Create invoices from excel workbook KJH Excel Worksheet Functions 5 December 22nd 04 02:21 PM


All times are GMT +1. The time now is 10:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"