-
Jan 18th, 2018, 07:34 PM
#1
Thread Starter
New Member
[RESOLVED] Question Excel Late Binding in VB 6
Hi,
i hope someone can explain it to me more exactly. I want a late binding of Excel in my Programm. So i set:
Dim myExcel as Object
Dim myWbk As Object
Const myTemplate As Long = 17
Set myExcel = CreateObject("excel.Application")
myExcel.Workbooks.OPEN (myTemplate)
myExcel.Visible = True
Set myWbk = myExcel.ActiveWorkbook
I do not know if I have to declare each property as an object before. Can someone give me an example for
ActiveSheet, Columns, Colum.ColumnWidth, Cells, Cells.font, cells.interior.colorindex and Range? Do I have to declare it all individually and assign with set? I did not understand the concept.
Thanks for your help!
-
Jan 18th, 2018, 07:50 PM
#2
Re: Question Excel Late Binding in VB 6
I've never seen the .OPEN method used that way. Typically, if you only have a single argument, it's a string, and it has the name and path of the Excel file you wish to open.
EDIT1: In fact, with the parentheses around the (myTemplate) like that, it's just creating (typecasting) myTemplate into a String, and trying to treat it as a file specification.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 18th, 2018, 09:44 PM
#3
Member
Re: Question Excel Late Binding in VB 6
-
Jan 19th, 2018, 05:23 AM
#4
Re: Question Excel Late Binding in VB 6
it would be better like
Code:
Set myExcel = CreateObject("excel.Application")
Set myWbk = myExcel.Workbooks.OPEN(myTemplate)
myExcel.Visible = True
you should always as far as possible avoid using select or active anything
any range including cells, columns etc, are range objects or collections of range objects, to assign any object to a variable requires use of the set keyword, this does not apply if using a for each loop
in most cases you do not need to assign object properties, to a variable to get or set them
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jan 20th, 2018, 10:07 PM
#5
Thread Starter
New Member
Re: Question Excel Late Binding in VB 6
thank you very much for all your help. Especially the link from kevin651212 is very good and has answered all my questions.
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
|