early vs. late binding to excel in VB6 
Author Message
 early vs. late binding to excel in VB6

hi,

does enybody know, how to replace ActiveWindow.DisplayGridlines = False in
early binding
to code in late binding?

simply : i want to turn off gridlines in sheet, but i'm using late binding
(without reference to excel object),
so ActiveWindows.DisplayGridlines = False doesn't work
thx

andy



Mon, 25 Jul 2011 03:59:25 GMT  
 early vs. late binding to excel in VB6
Could it be the typo ActiveWindows instead of ActiveWindow?
If that is not it, then best to post the relevant code, including all the
variable declarations.

RBS


Quote:
> hi,

> does enybody know, how to replace ActiveWindow.DisplayGridlines = False in
> early binding
> to code in late binding?

> simply : i want to turn off gridlines in sheet, but i'm using late binding
> (without reference to excel object),
> so ActiveWindows.DisplayGridlines = False doesn't work
> thx

> andy



Mon, 25 Jul 2011 04:42:03 GMT  
 early vs. late binding to excel in VB6
But he wrote it right the first time. So there's really no way of us knowing
if his code actually used ActiveWindow or ActiveWindows. And since he also
didn't mention any error that was raised, or much else really helpful, it's
anyone's guess.

Just another example of why you should ALWAYS *copy and paste* your code and
why you should ALWAYS state error messages, or something besides "it doesn't
work". "It doesn't work" doesn't tell us anything.

--
Mike


Quote:
> Could it be the typo ActiveWindows instead of ActiveWindow?
> If that is not it, then best to post the relevant code, including all the
> variable declarations.

> RBS



>> hi,

>> does enybody know, how to replace ActiveWindow.DisplayGridlines = False
>> in early binding
>> to code in late binding?

>> simply : i want to turn off gridlines in sheet, but i'm using late
>> binding (without reference to excel object),
>> so ActiveWindows.DisplayGridlines = False doesn't work
>> thx

>> andy



Mon, 25 Jul 2011 08:59:27 GMT  
 early vs. late binding to excel in VB6


Quote:
> hi,

> does enybody know, how to replace ActiveWindow.DisplayGridlines = False in
> early binding
> to code in late binding?

> simply : i want to turn off gridlines in sheet, but i'm using late binding
> (without reference to excel object),
> so ActiveWindows.DisplayGridlines = False doesn't work
> thx

Gotta give us more to go on.  As RB pointed out, you stated ActiveWindow one
time and ActiveWindows (note the "s") another. Copy and paste your actual
code!!

Are you getting some kind of error? If so, what is it?

It's irrelevant whether you're using early-binding or late-binding. The code
for this would be identical. The ONLY difference in code between the 2 is
how you declare the object variable and how you can instantiate it (and how
you instantiate doesn't even determine binding; it's the declaration that
determines that).

If you're using early-binding, you could instantiate it thusly:

Set oExcel = New Excel.Application

This requires you set a reference to the Excel Object Library in VB's
References dialog box. However, as mentioned, this does NOT make it
early-bound. To make it early-bound, you need to declare the variable as
such:

Dim oExcel As Excel.Application

If you declare the variable like this:

Dim oExcel As Object

then it's late-bound REGARDLESS of whether you instantiate it like this:

Set oExcel = New Excel.Application

or like this:

Set oExcel = CreateObject("Excel.Application").

(But the former still requires you have a reference to the library)

You could even have a reference to the library set in VB's References dialog
and do this:

Dim oExcel As Object
Set oExcel = New Excel.Application

This is STILL late-bound because the object variable is declared As Object.

For all subsequent code using that object variable, it's irrelevant whether
it's late-bound or early-bound.

I also don't buy into the "theories" that you should always use late-binding
for Office apps. What you should do (or can do) is early-bind to the
earliest version of Office you need to support. I've written VB6 apps 10
years ago and used early-binding against Office 97. These apps still work
fine with later versions of Office. Now that's not to say these apps
couldn't be updated to take advantage of things introduced in later versions
of Office. They could be, most definately.  But they still work having been
early-bound to Office 97. To this day, one of the first things I ask a
client (when writing an app for them which must use Automation with Office)
is what is the oldest version of Office a person using this app will have.
And that's the version I write against using early-binding.

Hopefully, that explains a little bit about early-binding and late-binding
since you don't appear to have a grasp of that.

--
Mike



Mon, 25 Jul 2011 09:39:54 GMT  
 early vs. late binding to excel in VB6
Change
ActiveWindow.DisplayGridlines = False
to
xlApp.ActiveWindow.DisplayGridlines = False

If you want to turn off gridlines in each sheet it's one of the few things
for which you do need to use Activate

for each oWs in xlApp.Activeworkbook.worksheets
xlApp.ActiveWindow.DisplayGridlines = False
next

where xlApp refers to your Excel instance.

Regards,
Peter T


Quote:
> hi,

> does enybody know, how to replace ActiveWindow.DisplayGridlines = False in
> early binding
> to code in late binding?

> simply : i want to turn off gridlines in sheet, but i'm using late binding
> (without reference to excel object),
> so ActiveWindows.DisplayGridlines = False doesn't work
> thx

> andy



Mon, 25 Jul 2011 21:57:29 GMT  
 early vs. late binding to excel in VB6
sorry,

it was my mistake, it is
ActiveWindow.DisplayGridlines = False

this worked, when i used early binding (with reference to excel 12 object
library)

i am using a late binding, with this code :
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

'Start a new workbook in Excel
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
oExcel.Visible = True

and so on

and ActiveWindow.DisplayGridlines = False doesn't work,
error message : run-time error 424
Object required.

as Peter T wrote, this worked : oExcel.ActiveWindow.DisplayGridlines = False

so

thank you

andy


Quote:
> Change
> ActiveWindow.DisplayGridlines = False
> to
> xlApp.ActiveWindow.DisplayGridlines = False

> If you want to turn off gridlines in each sheet it's one of the few things
> for which you do need to use Activate

> for each oWs in xlApp.Activeworkbook.worksheets
> xlApp.ActiveWindow.DisplayGridlines = False
> next

> where xlApp refers to your Excel instance.

> Regards,
> Peter T



>> hi,

>> does enybody know, how to replace ActiveWindow.DisplayGridlines = False
>> in early binding
>> to code in late binding?

>> simply : i want to turn off gridlines in sheet, but i'm using late
>> binding (without reference to excel object),
>> so ActiveWindows.DisplayGridlines = False doesn't work
>> thx

>> andy



Tue, 26 Jul 2011 01:48:55 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. early binding vs late binding

2. Activex Server - Early Binding vs. Late Binding

3. Late Binding vs Early Binding in out-of-process servers

4. early binding vs late binding

5. Early vs. Late binding

6. Early vs. Late binding in COM+

7. confused about late vs. early binding

8. * Early binding or late binding

9. Early binding and Late binding

10. early binding / late binding

11. Early binding and Late binding in VB.

12. Early Binding and Late Binding

 

 
Powered by phpBB® Forum Software