Link to home
Start Free TrialLog in
Avatar of Fritz Paul
Fritz PaulFlag for South Africa

asked on

Second call to open spreadsheet fro Access fails.

I use the VBA below to open an Excel workbook.
It opens and I close it again manually. The Excel window also closes.
If I try the process again, It does not open.
If I look on windows taskmanager, I see there is an Excel instance under processes. If I close that, the VBA works again one time.
Advice please.

My code is:
Private Sub cmdOpenExcelWorkbook_Click()
'   Open Excel Workbook
Dim excelApp As Excel.Application
Dim wb As Excel.Workbook
Dim WorkbookToOpen As String

    WorkbookToOpen = Me.txtOrigATD      'A textbox on my form
    Set excelApp = CreateObject("Excel.Application")
    Set wb = Excel.Workbooks.Open(WorkbookToOpen)
    excelApp.Visible = True
                '    wb.ActiveSheet.Range("d1").Value = 100     'Passes a value to a cell on the spreadsheet.

    Set excelApp = Nothing
    Set wb = Nothing
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fritz Paul

ASKER

Thanks, it's working.
glad I could help.