I have the following code, which works well individually:
Private Sub cmd_Export_Click()
DoCmd.OutputTo acOutputForm, "InterestCharge", acFormatXLS, "C:\InterestCharge.xls", False
Dim appExcel As Object
Dim workBook As Object
Dim workSheet As Object
' Open an existing spreadsheet
Set appExcel = GetObject("C:\InterestCharge.xls")
' Show spreadsheet on screen
appExcel.Application.Visible = True
appExcel.Parent.Windows(1).Visible = True
' Autofit all columns on a worksheet
Set workSheet = appExcel.Worksheets("InterestCharge")
With workSheet
.Range("G1").Value = "1"
.Range("G1").Copy
.Range("B2:F200").Select
.Range("B2:F200").PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, SkipBlanks:=False, Transpose:=False
.Range("G1").ClearContents
.Range("A1").Value = "Cost Centre"
.Range("B1").Value = "Interest Charge"
.Range("C1").Value = "DD"
.Range("D1").Value = "DD-1"
.Range("E1").Value = "DD-2"
.Range("F1").Value = "DD-3"
.Range("A1").Select
End With
' Release objects
Set workSheet = Nothing
Set workBook = Nothing
Set appExcel = Nothing
End Sub
However, when I ty to export the data and open Excel when Excel is already open nothing happens.
Any ideas on what I have to change?
Thanks
Private Sub cmd_Export_Click()
DoCmd.OutputTo acOutputForm, "InterestCharge", acFormatXLS, "C:\InterestCharge.xls", False
Dim appExcel As Object
Dim workBook As Object
Dim workSheet As Object
' Open an existing spreadsheet
Set appExcel = GetObject("C:\InterestCharge.xls")
' Show spreadsheet on screen
appExcel.Application.Visible = True
appExcel.Parent.Windows(1).Visible = True
' Autofit all columns on a worksheet
Set workSheet = appExcel.Worksheets("InterestCharge")
With workSheet
.Range("G1").Value = "1"
.Range("G1").Copy
.Range("B2:F200").Select
.Range("B2:F200").PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, SkipBlanks:=False, Transpose:=False
.Range("G1").ClearContents
.Range("A1").Value = "Cost Centre"
.Range("B1").Value = "Interest Charge"
.Range("C1").Value = "DD"
.Range("D1").Value = "DD-1"
.Range("E1").Value = "DD-2"
.Range("F1").Value = "DD-3"
.Range("A1").Select
End With
' Release objects
Set workSheet = Nothing
Set workBook = Nothing
Set appExcel = Nothing
End Sub
However, when I ty to export the data and open Excel when Excel is already open nothing happens.
Any ideas on what I have to change?
Thanks