Results 1 to 5 of 5

Thread: [RESOLVED] Question Excel Late Binding in VB 6

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    5

    Resolved [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!

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    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.

  3. #3
    Member
    Join Date
    Sep 2016
    Posts
    53

    Re: Question Excel Late Binding in VB 6


  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    5

    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
  •  



Click Here to Expand Forum to Full Width