Using Access 2003 and Excel
I've been around the block on this a couple of times (some postings on this site.) I have gotten to the point where I can populate a single Excel worksheet with data (simply by using ".Cell( intR, intC) = SOMEDATA, where intR and intC are the row and column references.)
But the minute I move into trying to do other Excel things - like copy and paste or underline - I run into problems. What's worse, some of what I try works and other stuff - which intuitively seems no different - doesn't. Example:
Private Sub Run_Click()
Dim objExcel As Object
Dim objSheet As Object
Dim objRange As Object
Set objExcel = CreateObject("Excel.Applic
ation")
objExcel.Visible = True
objExcel.DisplayAlerts = False
objExcel.Workbooks.Open "C:\Documents and Settings\wbeasom\Buck\Powe
rProject\V
elna1.xls"
--> objExcel.Workbooks.Sheet("
Sheet1").A
ctivate
'(Gives "Object Doesn't Support This Property Or Method)
With objExcel.ActiveSheet
.Range("A2,A4").Select
--> .Selection.Copy
'(Gives Same Error)
.Range("A3").Select
.Paste
End With
End Sub
I can't seem to select the sheet I want.
The first range command works, but the ".Selection.Copy" also blows up (Object doesn't support . . ."
When I try this:
With objExcel.ActiveSheet
.Range("A2,C2").Select
.Copy
.Range("A3,C3").Select
.Paste
End With
The copy seems to work (at least it doesn't blow up) but the second .Range command gives "Select Method of Range Class Failed."
I'm still trying to figure out how to do things like underline, change row height and column width and so forth.
Can anyone provide some guidance here or is there a resource of code snippets that will point me in the right direction. It seems that once I get some basic syntax straight I should be able to manipulate the Excel to my heart's content, but since I am using "Late Binding" it's pretty obvious that I can't just cut code out of Excel macros and use it in VBA.
Thanks in advance.
Start Free Trial