Get Cells Of A Range

  • Selected


    What you can do is when you do invoke your macro, the selected cells can be access doing the following:


    Worksheets("MySheet").Activate 'Activate the sheet with the selection
    ActiveSheet.Selection.Foo



    With cells, you can do whatever you need to do in VBA to the cells.
    You can also save the Range into a Range variable:


    Dim myRange as Range


    myRange = ActiveSheet.Selection

  • Quote from Jong

    What version of VB are you using.


    I can use the Range variable in 6.3


    vb 6.0
    i have to create a program that can take an excel file and present it with html(tables in html not excel in html)...the problem is that it must make html only the cells tha the user have chosen with the mouse...and i cannot find a way to take the selected cells...not the range...the first and the last cell... :(

  • Hi,


    If you are using VB6, the stand alone program, and want to manipulate Excel via code with early binding you will need to include a reference to the Excel Object library.
    Something like Excel9.olb


    This should then allow you to declare variables as type Range

    [h4]Cheers
    Andy
    [/h4]

  • Quote from Andy Pope

    Hi,


    If you are using VB6, the stand alone program, and want to manipulate Excel via code with early binding you will need to include a reference to the Excel Object library.
    Something like Excel9.olb


    This should then allow you to declare variables as type Range


    well thnx i found it :D but.....i get an error message when i write this...


    Dim myrange As Excel.Range
    myrange = ApExcel.Range("A1").Value = 11


    and i get


    "object variable or with block variable not set"


    help meeeeeeeeee :P plzzzz!!!!

  • You have created an instance of excel, haven't you?
    Or at least pointer to an open session.


    Dim appExcel as Excel.Application
    Set appExcel = CreateObject("Excel.Application")


    or


    Dim wbkTemp as Excel.Workbook
    Set wbkTemp = GetObject("MyFile.xls")


    Have a look at this article
    http://www.ozgrid.com/forum/showthread.php?t=19599


    Or this from Microsoft.
    http://support.microsoft.com/d…aspx?scid=kb;en-us;219151

    [h4]Cheers
    Andy
    [/h4]



  • Dim ApExcel As Object
    Dim a As String





    Private Sub Command1_Click()
    a = "c:\a.xls"
    Set ApExcel = CreateObject("Excel.application")
    ApExcel.Visible = True
    ApExcel.Workbooks.Open (a)


    End Sub


    thats what i have...can u give me suggestions or help to do it???i havent done anything yet....i really need help... :?

  • I suggest you try it as the code worked for me.


    I simply open a new VB stand-alone project. Add a command button to the userform.
    When I run the project and pressed the button it opened the workbook in another instance of excel.

    [h4]Cheers
    Andy
    [/h4]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!