How to select cells in Excel manipulated from VB
Lamont,
First, let me apologize for not understanding fully what you were asking.
Sometimes we get so involved with Excel and Access that we forget that
"access" has other meanings beside the database.
Does your UserForm have fields for specifying the Data Range? I do not see
anything in the code that specifies the desired Range. If the user needs to
specify the Range a couple of input boxes could be used for that (the first
asking for the beginning cell and the second asking for the ending cell.
Let me know if any of this makes sense.
--
Best wishes,
Jim
"Lamont" wrote:
It struck me that perhaps the "Select" command applies only to a mouse
operation by a user looking at the spreadsheet in Excel. So, since a range
object has a sort method, I tried Myrange.sort, where presumeably the range
implicitly "selects" the desired cells. This gets the error message "Method
'Range' of object '_Global' failed. So, my problem is not only inability to
select, bu to sort when manipulating and Excel spreadhseet by code from VB6.
--
Lamont Phemister
"Lamont" wrote:
Is it possible select a range of cells in an Excel spreadsheet under access
from a VB6 program?
The many permutations I have tried shown below fail.
Surely I should be able to Select a range of cells, because I have to do
this to sort the rows.
Thanks for kind assistance. Lamont
Private DataRange As Excel.Range
Private DataSheet As New Excel.Worksheet
Private MyWorkbook As New Excel.Workbook
Private Sub Command1_Click()
Dim strMyXLSBkSpec As String
Form1.Show
strMyXLSInSpec = "C:\DocData.xls" 'My spreadsheet
containing data about paper documents
Set MyWorkbook = GetObject(strMyXLSInSpec) 'This works to access my
Excel File
MyWorkbook.Activate 'this works
Set DataSheet = MyWorkbook.Sheets("DataSheet") 'this works
Set DataRange = DataSheet.UsedRange 'this works
Debug.Print DataRange.Rows.Count 'this works
DataSheet.Activate 'this works
'DataRange.Select 'Select method of range class failed.
'DataSheet.Range(1, 1).Select 'Method "Range" of object failed
'DataSheet.Cells(1, 1).Select 'Select method of range class failed.
'Set DataRange = Range(1, 1) 'Select method of range class failed.
'Cells.Select 'Select method of range class failed.
'DataSheet.Cells.Select 'Select method of range class failed.
'Set DataRange = Range(A1, A99) 'Select method of range class failed.
'Set DataRange = DataSheet.Range(A1, P99) 'Select method of range class
failed.
'Set DataRange = DataSheet.Range(1, 99) 'Select method of range class
failed.
End Sub
--
Lamont Phemister
|