I am trying to populate a spreadsheet using Access data, however I am having trouble with the line noted below, which is giving a run-time error. I am not familiar with the Excel Object Model, so not sure how the "selection, range, etc" should be used. Any help and guidance would be appreciated:

Dim xlApp As Excel.Application
        Dim xlWB As Excel.Workbook
        Dim xlWBold As Excel.Workbook
        Set xlApp = New Excel.Application
        With xlApp
            .Visible = True
            Set xlWB = .Workbooks.Open("C:\Users\Public\ABC.xls", , False)
            Set xlWBold = .Workbooks.Open("C:\Users\Public\DEF.xls", , False)
            '***Run-time error '91': Object variable or With block variable not set***
            xlApp.Range("B4", Selection.End(xlDown)).Select

            xlApp.Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, skipblanks _
                :=False, Transpose:=False
       End With


Re: Access / Excel VBA 80 80

The line after your run-time error should read:

xlApp.Range("B4", xlApp.Selection.End(xlDown)).Select

Either that, or just a simple period...the "Selection" object has to be in a context, whether that be the object in the "With" clause from above, or some other Excel.Application object.

Re: Access / Excel VBA 80 80

Adding xlApp. worked! Thank you so much for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.