ActiveX Basix

Boozer

Board Regular
Joined
May 20, 2002
Messages
52
Hello,

Just need some references for newbies to ActiveX. I am fairly good with Excel VB and need to know how to access that power from outside programs.

I have never used ActiveX before to create an excel sheet. I am now trying to use ActiveX to create an Excel spreadsheet with SecureCRT and VBscript. The example they gave to set this up was:

Set app = CreateObject("Excel.Application")
Set wb = app.Workbooks.Add
Set ws = wb.Worksheets(1)

But this confused me because of the .Add part. Everytime I use ws to do something, shouldn't that, in theory, add a workbook. I know from using it that it doesn't. I was wondering if the code I can use is limited by the program I am using, by Excel, or by ActiveX. Is there any simple way to reference things in excel just like I was writing code from excel VB editor? Any hints/tips/suggestions for a newbie would be greatly appreciated.

Thanks!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
What you're using is called "Late binding", because the "link" between your program and Excel is created at run time. If you set a reference to Excel (Using the References... command somewhere around there), you should be able to write code just like you do in VBA, for example

<pre>Sub Test()
Dim XlApp as Excel.Application
Dim WB as Excel.Workbook
Dim WS as Excel.Worksheet

Set XlApp = New Excel.Application
Set WB = XlApp.Workbooks.Add
Set WS = WB.Sheets(1)

MsgBox WS.Name
WB.Close False
XlApp.Quit
Set XlApp = Nothing
End Sub</pre>Note: Didn't test this, I just wrote this in here, but should work ok...
 
Upvote 0
On 2002-08-22 14:56, Boozer wrote:
...But this confused me because of the .Add part. Everytime I use ws to do something, shouldn't that, in theory, add a workbook...

Forgot this question. The answer as you found out is no, because you only create the workbook once, when you do the Set wb = , from then on, VB "knows" that the ws variable refers to (And only to) the first worksheet (or sheet) of the wb workbook. That's why it doesn't add a new workbook everytime.
 
Upvote 0
Thanks again for everyones help. But alas, I have another question.

I have no problem getting data to the worksheet, but is it possible to open a workbook and then call a VBScript or macro that is in that workbook?

Just for example:

Lets say I have an extravagent script already written in Excel to manipulate data. Now the data source changed and I have to learn activex interface commands to get the data to Excel. Do I also have to re-code the data manipulation in the external program, or can I send the data to excel and then somehow call the script already in excel to manipulate the data for me.

I know I can just have the script run when the Excel spreadsheet is opened, but I would like to have all the data manipulation completed automatically when the data is entered with the script already in Excel.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,755
Members
449,049
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top