Hi
I create an Excel workbook from Access and this contains some exported data. I am then trying to change various cells in the worksheet so that it is essentially a finished product. I am doing this by recording a macro and then using some of that code in Access.
This is Access 2003 and Excel 2003.
The problem is that the code created by the macro is not recognised by Access and I cannot understand why as it is all essentially VBA.
Some code below:
' Open an existing spreadsheet
Call Shell("C:\Program Files\Microsoft Office\Office11\excel.EXE " & "C:\A.xls", 1)
Set appExcel = CreateObject("C:\A.xls")
Set workSheet = appExcel.Worksheets("A")
' Show spreadsheet on screen
appExcel.Application.Visible = True
appExcel.Parent.Windows(1).Visible = True
With workSheet
.Range("A30").Value = "1"
.Range("A30").Copy
.Range("B2:BI13").Select
.Range("B2:BI13").PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, SkipBlanks:=False, Transpose:=False
.Range("A30").ClearContents
'.Range("P:BJ").Delete Shift:=xlToLeft
.Range("B1").Value = "Company Code"
.Range("L1").Value = "DD"
.Range("M1").Value = "DD-1"
.Range("N1").Value = "DD-2"
.Range("O1").Value = "DD-3"
.Range("B13").Select
.Selection.Copy
.Range("B14").Select
.ActiveSheet.Paste
End With
The debugger highlights this line:
.Selection.Copy
and the error is object doesn't support this property or method.
I have got round this by doing things like .Range("B13").Copy, etc. but would ideally just like to paste the macro entirely.
ANy ideas on what is wrong?
I create an Excel workbook from Access and this contains some exported data. I am then trying to change various cells in the worksheet so that it is essentially a finished product. I am doing this by recording a macro and then using some of that code in Access.
This is Access 2003 and Excel 2003.
The problem is that the code created by the macro is not recognised by Access and I cannot understand why as it is all essentially VBA.
Some code below:
' Open an existing spreadsheet
Call Shell("C:\Program Files\Microsoft Office\Office11\excel.EXE " & "C:\A.xls", 1)
Set appExcel = CreateObject("C:\A.xls")
Set workSheet = appExcel.Worksheets("A")
' Show spreadsheet on screen
appExcel.Application.Visible = True
appExcel.Parent.Windows(1).Visible = True
With workSheet
.Range("A30").Value = "1"
.Range("A30").Copy
.Range("B2:BI13").Select
.Range("B2:BI13").PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, SkipBlanks:=False, Transpose:=False
.Range("A30").ClearContents
'.Range("P:BJ").Delete Shift:=xlToLeft
.Range("B1").Value = "Company Code"
.Range("L1").Value = "DD"
.Range("M1").Value = "DD-1"
.Range("N1").Value = "DD-2"
.Range("O1").Value = "DD-3"
.Range("B13").Select
.Selection.Copy
.Range("B14").Select
.ActiveSheet.Paste
End With
The debugger highlights this line:
.Selection.Copy
and the error is object doesn't support this property or method.
I have got round this by doing things like .Range("B13").Copy, etc. but would ideally just like to paste the macro entirely.
ANy ideas on what is wrong?
Last edited: