Manipulate Excel worksheet from Access

  • Thread starter Thread starter grace
  • Start date Start date
G

grace

Guest
I have generated some data using a cross-tab query and exported them into Excel. Now I need to open this excel file directly from current database and delete two columns from and then save it. I can see worksheet with C & D columns highlighted. But my code is not able to clear the contents. Please help!!!!!!!!

dim Myxl as object
Dim oWS As Object
'strAppPath is my excel file address
Set MyXL = GetObject(strAppPath)
MyXL.workbooks.Edit
MyXL.Application.Visible = True
MyXL.Parent.windows(1).Visible = True
beep
Set oWS = MyXL.activesheet

With oWS
.columns("C
biggrin.gif
").select
.Selection.ClearContents
End With
MyXL.ActiveWorkbook.Save

set ows = nothing
Set MyXL = Nothing
 
You have to start from the parent object then drill down to the object you want the event to happen to.
Worksheets("Sheet1").Range("C1
biggrin.gif
37").Clear
 
use:

Dim Myxl As Object
'strAppPath is my excel file address
Set Myxl = GetObject("C:\TMP\TMP.XLS")
with Myxl
.Application.Visible = True
.Parent.windows(1).Visible = True
.activesheet.Range("C:C").ClearContents
.ActiveWorkbook.Save
end with
Set oWS = Nothing
Set Myxl = Nothing
 

Users who are viewing this thread

Back
Top Bottom